-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace ngx-translate with transloco
use transloco as better maintained tool;
- Loading branch information
1 parent
9b2c5c5
commit bcc28c0
Showing
14 changed files
with
415 additions
and
164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"HELLO": "Hello, {{value}} component en" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"HELLO": "Hello, {{value}} component ru" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
{ | ||
"HELLO": "Hello, {{value}}" | ||
} | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface TranslocoLocalScope { | ||
getTranslocoScope: () => string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const SUPPORTED_LANGUAGES = [ | ||
'en', | ||
'ru' | ||
] | ||
export const DEFAULT_LANGUAGE = SUPPORTED_LANGUAGES[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
Injectable | ||
} from '@angular/core' | ||
import { | ||
InlineLoader, | ||
Translation, | ||
TranslocoLoader | ||
} from '@ngneat/transloco' | ||
import { | ||
HttpClient | ||
} from '@angular/common/http' | ||
import { | ||
SUPPORTED_LANGUAGES | ||
} from './transloco-languages' | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TranslocoHttpLoader implements TranslocoLoader { | ||
constructor(private http: HttpClient) {} | ||
|
||
getTranslation(lang: string) { | ||
return this.http.get<Translation>(`/assets/i18n/${lang}.json`) | ||
} | ||
} | ||
|
||
export function getTranslocoInlineLoader(getLanguageLoader: (lang: string) => (() => Promise<Translation>)) { | ||
return SUPPORTED_LANGUAGES.reduce<InlineLoader>((acc: InlineLoader, lang: string) => { | ||
acc[lang] = getLanguageLoader(lang) | ||
return acc | ||
}, {} as InlineLoader) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
Translation, | ||
TranslocoTestingModule | ||
} from '@ngneat/transloco' | ||
import { | ||
TranslocoLocalScope | ||
} from './transloco-interfaces' | ||
|
||
export function getTranslocoTestingModule(componentClass: TranslocoLocalScope, translations: Translation) { | ||
const testingLang = 'en' | ||
const scope = componentClass.getTranslocoScope() | ||
return TranslocoTestingModule.forRoot({ | ||
langs: { | ||
[`${scope}/${testingLang}`]: translations | ||
}, | ||
translocoConfig: { | ||
defaultLang: testingLang, | ||
availableLangs: [testingLang] | ||
}, | ||
preloadLangs: true | ||
}) | ||
} |