Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Howto write a HashTranslateLoader #39

Merged
merged 2 commits into from
Mar 16, 2018
Merged

Conversation

seveves
Copy link
Contributor

@seveves seveves commented Jan 30, 2018

In issue #25 @mlegenhausen pointed out a solution that shows a very common use-case for a custom TranslateLoader implementation.
Maybe we can extend the readme to show this (and maybe other use-cases in the future)?

Kind regards :)

PS: my english is not the best, so feel free to improve it in any way

In issue ngx-translate#25 @mlegenhausen pointed out a solution that shows a very common use-case for a custom TranslateLoader implementation.
Maybe we can extend the readme to show this (and maybe other use-cases in the future)?

Kind regards :)
Copy link

@tiaguinho tiaguinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seveves please, make this changes in your PR.

README.md Outdated
@@ -69,3 +69,47 @@ export function HttpLoaderFactory(http: HttpClient) {
```

For now this loader only support the json format.

## Custom TranslateLoader strategies
### HashTranslateLoader - Hashing translation files with angular-cli, webpack and SystemJS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the line 74 and change the title to Angular CLI/Webpack TranslateLoader Example

README.md Outdated
}
```

When your project cannot find `System` then adding this to your `typings.d.ts` file helps:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cause System will not be available you need to add it to your custom typings.d.ts

README.md Outdated
import { TranslateLoader } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';

export class HashTranslateLoader implements TranslateLoader {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more accurate changing the class name to WebpackTranslateLoader.

README.md Outdated
export class AppModule { }
```

One disadvantage of this solution is that you have to rebuild your application when there are only changes inside your language files.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think will be better changed to:

The disadvantage of this solution is that you have to rebuild the application everytime your translate files has changes.

README.md Outdated

## Custom TranslateLoader strategies
### HashTranslateLoader - Hashing translation files with angular-cli, webpack and SystemJS
Allow caching of translation files by the browser could help to speed up the initial load of your app but with the default setup your translation files could miss the latest changes because the cache doesn't have the latest version of your translation file yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this line.

README.md Outdated
### HashTranslateLoader - Hashing translation files with angular-cli, webpack and SystemJS
Allow caching of translation files by the browser could help to speed up the initial load of your app but with the default setup your translation files could miss the latest changes because the cache doesn't have the latest version of your translation file yet.

When using the angular-cli (uses webpack under the hood) you can write your own `TranslateLoader` that always loads the latest translation file available during your application build.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using Angular CLI.....

@seveves
Copy link
Contributor Author

seveves commented Mar 16, 2018

@tiaguinho thank you for your review. I've updated the file to your suggestions.

@ocombe ocombe merged commit 3f59877 into ngx-translate:master Mar 16, 2018
@ocombe
Copy link
Member

ocombe commented Mar 16, 2018

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants