Skip to content

Commit

Permalink
Update: Rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
arunredhu committed Feb 8, 2020
2 parents 2c4f58c + 4a8a636 commit d90118d
Show file tree
Hide file tree
Showing 19 changed files with 10,553 additions and 7,522 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [ocombe]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ notifications:
node_js:
- '10'
before_install:
- export CHROME_BIN=chromium-browser
- if [[ `npm -v` != 6* ]]; then npm i -g npm@6; fi
services:
- xvfb
addons:
chrome: stable
after_success:
- npm run build
- cp .git dist/@ngx-translate/core/ -r # required by semantic release
Expand All @@ -17,6 +20,3 @@ after_success:
branches:
except:
- /^v\d+\.\d+\.\d+$/
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
7 changes: 4 additions & 3 deletions FIREBASE_EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { Observable } from 'rxjs/Observable';
import { AngularFireDatabase} from 'angularfire2/database';

export class FirebaseTransLoader implements TranslateLoader {
constructor(private db: AngularFireDatabase) {}
public getTranslation(lang: string, prefix: string = 'translations/'): any {
return this.db.object(`${prefix}${lang}`) as Observable<any>;
constructor(private db: AngularFireDatabase, private prefix: string = 'translations/') {}
public getTranslation(lang: string): any {
return this.db.object(`${this.prefix}${lang}`) as Observable<any>;

}
}
```
Expand Down
14 changes: 13 additions & 1 deletion MIGRATION_GUIDE_5_TO_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,20 @@ If you don't use this loader, go directly to point 5.
missingTranslationHandler: {provide: MissingTranslationHandler, useClass: CustomHandler}
})
```

7. If you call the new `TranslateHttpLoader`, make sure your `prefix` parameter ends in a slash.

```ts
new TranslateStaticLoader(http, "/custom-dir/assets/i18n", "-lang.json");
```

Is now:

```ts
new TranslateHttpLoader(http, "/custom-dir/assets/i18n/", "-lang.json");
```

7. If you use lazy loaded modules, a new `forChild` method has been added.
8. If you use lazy loaded modules, a new `forChild` method has been added.
It has the benefit to declare the pipe/directive/service for your module, but it doesn't declare a new instance of the `TranslateStore`.
In this new release, the store has been added to link all instances of the service. It is used behind the scenes by the service and you don't have to use it yourself.

Expand Down
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@ Get the complete changelog here: https://github.com/ngx-translate/core/releases
## Table of Contents
* [Installation](#installation)
* [Usage](#usage)
* [Import the TranslateModule](#1-import-the-translatemodule)
* [SharedModule](#sharedmodule)
* [Lazy loaded modules](#lazy-loaded-modules)
* [Configuration](#configuration)
* [AoT](#aot)
* [Init the TranslateService for your application](#2-init-the-translateservice-for-your-application)
* [Define the translations](#3-define-the-translations)
* [Use the service, the pipe or the directive](#4-use-the-service-the-pipe-or-the-directive)
* [Use HTML tags](#5-use-html-tags)
* [API](#api)
* [TranslateService](#translateservice)
* [Properties](#properties)
* [Methods](#methods)
* [Write & use your own loader](#write--use-your-own-loader)
* [Example](#example)
* [How to use a compiler to preprocess translation values](#how-to-use-a-compiler-to-preprocess-translation-values)
* [How to handle missing translations](#how-to-handle-missing-translations)
* [Example](#example-1)
* [Parser](#parser)
* [Methods](#methods)
* [FAQ](#faq)
* [I'm getting an error `npm ERR! peerinvalid Peer [...]`](#im-getting-an-error-npm-err-peerinvalid-peer-)
* [Plugins](#plugins)
* [Editors](#editors)
* [Additional Framework Support](#additional-framework-support)
Expand All @@ -28,7 +48,8 @@ Choose the version corresponding to your Angular version:

Angular | @ngx-translate/core | @ngx-translate/http-loader
----------- | ------------------- | --------------------------
7/8 | 11.x+ | 4.x+
8 | 12.x+ | 4.x+
7 | 11.x+ | 4.x+
6 | 10.x | 3.x
5 | 8.x to 9.x | 1.x to 2.x
4.3 | 7.x or less | 1.x to 2.x
Expand Down Expand Up @@ -87,6 +108,10 @@ export class SharedModule { }
When you lazy load a module, you should use the `forChild` static method to import the `TranslateModule`.

Since lazy loaded modules use a different injector from the rest of your application, you can configure them separately with a different loader/compiler/parser/missing translations handler.

To make a child module extend translations from parent modules use `extend: true`. This will cause the service to also
use translations from its parent module.

You can also isolate the service by using `isolate: true`. In which case the service is a completely isolated instance (for translations, current lang, events, ...).
Otherwise, by default, it will share its data with other instances of the service (but you can still use a different loader/compiler/parser/handler even if you don't isolate the service).

Expand Down Expand Up @@ -276,6 +301,39 @@ And in your component define `param` like this:
param = {value: 'world'};
```

You can construct the translation keys dynamically by using simple string concatenation inside the template:

```html
<ul *ngFor="let language of languages">
<li>{{ 'LANGUAGES.' + language | translate }}</li>
</ul>
```

Where `languages` is an array member of your component:

```ts
languages = ['EN', 'FR', 'BG'];
```

You can also use the output of the built-in pipes `uppercase` and `lowercase` in order to guarantee that your dynamically generated translation keys are either all uppercase or all lowercase. For example:

```html
<p>{{ 'ROLES.' + role | uppercase | translate }}</p>
```

```ts
role = 'admin';
```

will match the following translation:
```json
{
"ROLES": {
"ADMIN": "Administrator"
}
}
```

This is how you use the **directive**:
```html
<div [translate]="'HELLO'" [translateParams]="{value: 'world'}"></div>
Expand Down Expand Up @@ -345,6 +403,7 @@ To render them, simply use the `innerHTML` attribute with the pipe on any elemen
- `addLangs(langs: Array<string>)`: Add new langs to the list
- `getLangs()`: Returns an array of currently available langs
- `get(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>`: Gets the translated value of a key (or an array of keys) or the key if the value was not found
- `getStreamOnTranslationChange(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>`: Returns a stream of translated values of a key (or an array of keys) or the key if the value was not found. Without any `onTranslationChange` events this returns the same value as `get` but it will also emit new values whenever the translation changes.
- `stream(key: string|Array<string>, interpolateParams?: Object): Observable<string|Object>`: Returns a stream of translated values of a key (or an array of keys) or the key if the value was not found. Without any `onLangChange` events this returns the same value as `get` but it will also emit new values whenever the used language changes.
- `instant(key: string|Array<string>, interpolateParams?: Object): string|Object`: Gets the instant translated value of a key (or an array of keys). /!\ This method is **synchronous** and the default file loader is asynchronous. You are responsible for knowing when your translations have been loaded and it is safe to use this method. If you are not sure then you should use the `get` method instead.
- `set(key: string, value: string, lang?: string)`: Sets the translated value of a key
Expand Down Expand Up @@ -388,7 +447,7 @@ export class AppModule { }
By default, translation values are added "as-is". You can configure a `compiler` that implements `TranslateCompiler` to pre-process translation values when they are added (either manually or by a loader). A compiler has the following methods:

- `compile(value: string, lang: string): string | Function`: Compiles a string to a function or another string.
- `compileTranslations(translations: any, lang: string): any`: Compiles a (possibly nested) object of translation values to a structurally identical object of compiled translation values.
- `compileTranslations(translations: any, lang: string): any`: Compiles a (possibly nested) object of translation values to a structurally identical object of compiled translation values.
Using a compiler opens the door for powerful pre-processing of translation values. As long as the compiler outputs a compatible interpolation string or an interpolation function, arbitrary input syntax can be supported.
Expand Down Expand Up @@ -454,6 +513,9 @@ If you're already on npm 3, check if it's an error (`npm ERR!`) or a warning (`n
If you're using an old version of Angular and ngx-translate requires a newer version then you should consider upgrading your application to use the newer angular 2 version. There is always a reason when I upgrade the minimum dependencies of the library. Often it is because Angular had a breaking changes. If it's not an option for you, then check [the changelog](/releases) to know which version is the last compatible version for you.
#### I want to hot reload the translations in my application but `reloadLang` does not work
If you want to reload the translations and see the update on all your components without reloading the page, you have to load the translations manually and call `setTranslation` function which triggers `onTranslationChange`.
## Plugins
- [Localize Router](https://github.com/Greentube/localize-router) by @meeroslav: An implementation of routes localization for Angular. If you need localized urls (for example /fr/page and /en/page).
Expand All @@ -466,6 +528,8 @@ If you're using an old version of Angular and ngx-translate requires a newer ver
- [ngx-translate-module-loader](https://github.com/larscom/ngx-translate-module-loader) by @larscom: Fetch multiple translation files (http) with ngx-translate. Each translation file gets it's own namespace out of the box and the configuration is very flexible.
- [ngx-translate-all](https://github.com/irustm/ngx-translate-all) by @irustm: Automate translations for Angular projects.
- [ngx-translate-migrate](https://github.com/irustm/ngx-translate-migrate) by @irustm: Automate migrations from ngx-translate to Angular i18n.
- [ngx-translate-lint](https://github.com/svoboda-rabstvo/ngx-translate-lint) by @svoboda-rabstvo: Simple CLI tools for check ngx-translate keys in whole app
- [ngx-translate-cut](https://github.com/bartholomej/ngx-translate-cut) by @bartholomej: Simple and useful pipe for cutting translations ✂️
## Editors
- [BabelEdit](https://www.codeandweb.com/babeledit) — translation editor for JSON files
Expand Down
Loading

0 comments on commit d90118d

Please sign in to comment.