diff --git a/integration/_payload-limits.json b/integration/_payload-limits.json index 9773f8a944..e091e55979 100644 --- a/integration/_payload-limits.json +++ b/integration/_payload-limits.json @@ -12,7 +12,7 @@ "master": { "uncompressed": { "runtime": 1440, - "main": 13266, + "main": 13264, "polyfills": 45340 } } diff --git a/packages/core/src/core_render3_private_export.ts b/packages/core/src/core_render3_private_export.ts index 6834da55f7..753437e007 100644 --- a/packages/core/src/core_render3_private_export.ts +++ b/packages/core/src/core_render3_private_export.ts @@ -168,7 +168,6 @@ export { ɵɵi18nEnd, ɵɵi18nApply, ɵɵi18nPostprocess, - i18nConfigureLocalize as ɵi18nConfigureLocalize, setLocaleId as ɵsetLocaleId, setClassMetadata as ɵsetClassMetadata, ɵɵresolveWindow, diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index baea1b2d36..34cc2757b2 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -12,7 +12,6 @@ import {InertBodyHelper} from '../sanitization/inert_body'; import {_sanitizeUrl, sanitizeSrcset} from '../sanitization/url_sanitizer'; import {addAllToArray} from '../util/array_utils'; import {assertDataInRange, assertDefined, assertEqual, assertGreaterThan} from '../util/assert'; -import {global} from '../util/global'; import {attachPatchData} from './context_discovery'; import {bind, setDelayProjection} from './instructions/all'; import {attachI18nOpCodesDebug} from './instructions/lview_debug'; @@ -1317,88 +1316,6 @@ function replaceNgsp(value: string): string { return value.replace(NGSP_UNICODE_REGEXP, ' '); } -export interface I18nLocalizeOptions { translations: {[key: string]: string}; } - -/** - * Provide translations for `$localize`. - * - * @deprecated this method is temporary & should not be used as it will be removed soon - */ -export function i18nConfigureLocalize(options: I18nLocalizeOptions = { - translations: {} -}) { - type TranslationInfo = {messageParts: TemplateStringsArray, placeholderNames: string[]}; - type MessageInfo = {translationKey: string, replacements: {[placeholderName: string]: any}}; - const PLACEHOLDER_MARKER = ':'; - const TRANSLATIONS: {[key: string]: TranslationInfo} = {}; - - Object.keys(options.translations).forEach(key => { - TRANSLATIONS[key] = splitMessage(options.translations[key]); - }); - - if (ngDevMode) { - if (global.$localize === undefined) { - throw new Error( - 'The global function `$localize` is missing. Please add `import \'@angular/localize\';` to your polyfills.ts file.'); - } - } - $localize.translate = function(messageParts: TemplateStringsArray, expressions: readonly any[]): - [TemplateStringsArray, readonly any[]] { - const message = parseMessage(messageParts, expressions); - const translation = TRANSLATIONS[message.translationKey]; - const result: [TemplateStringsArray, readonly any[]] = - (translation === undefined ? [messageParts, expressions] : [ - translation.messageParts, - translation.placeholderNames.map(placeholder => message.replacements[placeholder]) - ]); - return result; - }; - - function splitMessage(message: string): TranslationInfo { - const parts = message.split(/{\$([^}]*)}/); - const messageParts = [parts[0]]; - const placeholderNames: string[] = []; - for (let i = 1; i < parts.length - 1; i += 2) { - placeholderNames.push(parts[i]); - messageParts.push(parts[i + 1]); - } - const rawMessageParts = - messageParts.map(part => part.charAt(0) === PLACEHOLDER_MARKER ? '\\' + part : part); - return {messageParts: makeTemplateObject(messageParts, rawMessageParts), placeholderNames}; - } - - function parseMessage( - messageParts: TemplateStringsArray, expressions: readonly any[]): MessageInfo { - const PLACEHOLDER_NAME_MARKER = ':'; - const replacements: {[placeholderName: string]: any} = {}; - let translationKey = messageParts[0]; - for (let i = 1; i < messageParts.length; i++) { - const messagePart = messageParts[i]; - const expression = expressions[i - 1]; - // There is a problem with synthesized template literals in TS where the raw version - // cannot be found, since there is no original source code to read it from. - // In that case we just fall back on the non-raw version. - // This should be OK because synthesized nodes (from the template compiler) will always have - // placeholder names provided. - if ((messageParts.raw[i] || messagePart).charAt(0) === PLACEHOLDER_NAME_MARKER) { - const endOfPlaceholderName = messagePart.indexOf(PLACEHOLDER_NAME_MARKER, 1); - const placeholderName = messagePart.substring(1, endOfPlaceholderName); - translationKey += `{$${placeholderName}}${messagePart.substring(endOfPlaceholderName + 1)}`; - replacements[placeholderName] = expression; - } else { - translationKey += messagePart; - replacements[`ph_${i}`] = expression; - } - } - return {translationKey, replacements}; - } - - function makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray { - Object.defineProperty(cooked, 'raw', {value: raw}); - return cooked as any; - } -} - /** * The locale id that the application is currently using (for translations and ICU expressions). * This is the ivy version of `LOCALE_ID` that was defined as an injection token for the view engine diff --git a/packages/core/src/render3/index.ts b/packages/core/src/render3/index.ts index d1752af3bb..48a304a6bf 100644 --- a/packages/core/src/render3/index.ts +++ b/packages/core/src/render3/index.ts @@ -148,7 +148,6 @@ export { ɵɵi18nEnd, ɵɵi18nApply, ɵɵi18nPostprocess, - i18nConfigureLocalize, getLocaleId, setLocaleId, } from './i18n'; diff --git a/packages/core/test/acceptance/BUILD.bazel b/packages/core/test/acceptance/BUILD.bazel index e87138061b..db2a0e28be 100644 --- a/packages/core/test/acceptance/BUILD.bazel +++ b/packages/core/test/acceptance/BUILD.bazel @@ -19,6 +19,8 @@ ts_library( "//packages/core", "//packages/core/src/util", "//packages/core/testing", + "//packages/localize", + "//packages/localize/run_time", "//packages/platform-browser", "//packages/platform-browser-dynamic", "//packages/platform-browser/animations", diff --git a/packages/core/test/acceptance/i18n_spec.ts b/packages/core/test/acceptance/i18n_spec.ts index e0f5335bfc..13ff777e95 100644 --- a/packages/core/test/acceptance/i18n_spec.ts +++ b/packages/core/test/acceptance/i18n_spec.ts @@ -8,9 +8,10 @@ import '@angular/localize'; import {registerLocaleData} from '@angular/common'; import localeRo from '@angular/common/locales/ro'; -import {Component, ContentChild, ContentChildren, Directive, HostBinding, Input, LOCALE_ID, QueryList, TemplateRef, Type, ViewChild, ViewContainerRef, ɵi18nConfigureLocalize, Pipe, PipeTransform} from '@angular/core'; +import {Component, ContentChild, ContentChildren, Directive, HostBinding, Input, LOCALE_ID, QueryList, TemplateRef, Type, ViewChild, ViewContainerRef, Pipe, PipeTransform} from '@angular/core'; import {setDelayProjection} from '@angular/core/src/render3/instructions/projection'; import {TestBed} from '@angular/core/testing'; +import {loadTranslations} from '@angular/localize/run_time'; import {By} from '@angular/platform-browser'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {onlyInIvy} from '@angular/private/testing'; @@ -24,14 +25,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { afterEach(() => { setDelayProjection(false); }); it('should translate text', () => { - ɵi18nConfigureLocalize({translations: {'text': 'texte'}}); + loadTranslations({'text': 'texte'}); const fixture = initWithTemplate(AppComp, `
text
`); expect(fixture.nativeElement.innerHTML).toEqual(`
texte
`); }); it('should support interpolations', () => { - ɵi18nConfigureLocalize( - {translations: {'Hello {$interpolation}!': 'Bonjour {$interpolation}!'}}); + loadTranslations({'Hello {$interpolation}!': 'Bonjour {$interpolation}!'}); const fixture = initWithTemplate(AppComp, `
Hello {{name}}!
`); expect(fixture.nativeElement.innerHTML).toEqual(`
Bonjour Angular!
`); fixture.componentRef.instance.name = `John`; @@ -40,11 +40,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support named interpolations', () => { - ɵi18nConfigureLocalize({ - translations: { - ' Hello {$userName}! Emails: {$amountOfEmailsReceived} ': - ' Bonjour {$userName}! Emails: {$amountOfEmailsReceived} ' - } + loadTranslations({ + ' Hello {$userName}! Emails: {$amountOfEmailsReceived} ': + ' Bonjour {$userName}! Emails: {$amountOfEmailsReceived} ' }); const fixture = initWithTemplate(AppComp, `
@@ -60,7 +58,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support interpolations with custom interpolation config', () => { - ɵi18nConfigureLocalize({translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); const interpolation = ['{%', '%}'] as[string, string]; TestBed.overrideComponent(AppComp, {set: {interpolation}}); const fixture = initWithTemplate(AppComp, `
Hello {% name %}
`); @@ -70,17 +68,15 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { it('should support &ngsp; in translatable sections', () => { // note: the `` unicode symbol represents the `&ngsp;` in translations - ɵi18nConfigureLocalize({translations: {'text ||': 'texte ||'}}); + loadTranslations({'text ||': 'texte ||'}); const fixture = initWithTemplate(AppCompWithWhitespaces, `
text |&ngsp;|
`); expect(fixture.nativeElement.innerHTML).toEqual(`
texte | |
`); }); it('should support interpolations with complex expressions', () => { - ɵi18nConfigureLocalize({ - translations: - {'{$interpolation} - {$interpolation_1}': '{$interpolation} - {$interpolation_1} (fr)'} - }); + loadTranslations( + {'{$interpolation} - {$interpolation_1}': '{$interpolation} - {$interpolation_1} (fr)'}); const fixture = initWithTemplate(AppComp, `
{{ name | uppercase }} - {{ obj?.a?.b }}
`); expect(fixture.nativeElement.innerHTML).toEqual(`
ANGULAR - (fr)
`); @@ -90,11 +86,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support elements', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Hello {$startTagSpan}world{$closeTagSpan} and {$startTagDiv}universe{$closeTagDiv}!': - 'Bonjour {$startTagSpan}monde{$closeTagSpan} et {$startTagDiv}univers{$closeTagDiv}!' - } + loadTranslations({ + 'Hello {$startTagSpan}world{$closeTagSpan} and {$startTagDiv}universe{$closeTagDiv}!': + 'Bonjour {$startTagSpan}monde{$closeTagSpan} et {$startTagDiv}univers{$closeTagDiv}!' }); const fixture = initWithTemplate( AppComp, `
Hello world and
universe
!
`); @@ -103,11 +97,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support removing elements', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Hello {$startBoldText}my{$closeBoldText}{$startTagSpan}world{$closeTagSpan}': - 'Bonjour {$startTagSpan}monde{$closeTagSpan}' - } + loadTranslations({ + 'Hello {$startBoldText}my{$closeBoldText}{$startTagSpan}world{$closeTagSpan}': + 'Bonjour {$startTagSpan}monde{$closeTagSpan}' }); const fixture = initWithTemplate(AppComp, `
Hello myworld
!
`); @@ -116,11 +108,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support moving elements', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Hello {$startTagSpan}world{$closeTagSpan} and {$startTagDiv}universe{$closeTagDiv}!': - 'Bonjour {$startTagDiv}univers{$closeTagDiv} et {$startTagSpan}monde{$closeTagSpan}!' - } + loadTranslations({ + 'Hello {$startTagSpan}world{$closeTagSpan} and {$startTagDiv}universe{$closeTagDiv}!': + 'Bonjour {$startTagDiv}univers{$closeTagDiv} et {$startTagSpan}monde{$closeTagSpan}!' }); const fixture = initWithTemplate( AppComp, `
Hello world and
universe
!
`); @@ -129,11 +119,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support template directives', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Content: {$startTagDiv}before{$startTagSpan}middle{$closeTagSpan}after{$closeTagDiv}!': - 'Contenu: {$startTagDiv}avant{$startTagSpan}milieu{$closeTagSpan}après{$closeTagDiv}!' - } + loadTranslations({ + 'Content: {$startTagDiv}before{$startTagSpan}middle{$closeTagSpan}after{$closeTagDiv}!': + 'Contenu: {$startTagDiv}avant{$startTagSpan}milieu{$closeTagSpan}après{$closeTagDiv}!' }); const fixture = initWithTemplate( AppComp, @@ -151,14 +139,12 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support multiple i18n blocks', () => { - ɵi18nConfigureLocalize({ - translations: { - 'trad {$interpolation}': 'traduction {$interpolation}', - 'start {$interpolation} middle {$interpolation_1} end': - 'start {$interpolation_1} middle {$interpolation} end', - '{$startTagC}trad{$closeTagC}{$startTagD}{$closeTagD}{$startTagE}{$closeTagE}': - '{$startTagE}{$closeTagE}{$startTagC}traduction{$closeTagC}' - } + loadTranslations({ + 'trad {$interpolation}': 'traduction {$interpolation}', + 'start {$interpolation} middle {$interpolation_1} end': + 'start {$interpolation_1} middle {$interpolation} end', + '{$startTagC}trad{$closeTagC}{$startTagD}{$closeTagD}{$startTagE}{$closeTagE}': + '{$startTagE}{$closeTagE}{$startTagC}traduction{$closeTagC}' }); const fixture = initWithTemplate(AppComp, `
@@ -176,12 +162,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support multiple sibling i18n blocks', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Section 1': 'Section un', - 'Section 2': 'Section deux', - 'Section 3': 'Section trois', - } + loadTranslations({ + 'Section 1': 'Section un', + 'Section 2': 'Section deux', + 'Section 3': 'Section trois', }); const fixture = initWithTemplate(AppComp, `
@@ -194,12 +178,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support multiple sibling i18n blocks inside of a template directive', () => { - ɵi18nConfigureLocalize({ - translations: { - 'Section 1': 'Section un', - 'Section 2': 'Section deux', - 'Section 3': 'Section trois', - } + loadTranslations({ + 'Section 1': 'Section un', + 'Section 2': 'Section deux', + 'Section 3': 'Section trois', }); const fixture = initWithTemplate(AppComp, `
    @@ -215,10 +197,8 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should properly escape quotes in content', () => { - ɵi18nConfigureLocalize({ - translations: { - '\'Single quotes\' and "Double quotes"': '\'Guillemets simples\' et "Guillemets doubles"' - } + loadTranslations({ + '\'Single quotes\' and "Double quotes"': '\'Guillemets simples\' et "Guillemets doubles"' }); const fixture = initWithTemplate(AppComp, `
    'Single quotes' and "Double quotes"
    `); @@ -228,7 +208,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should correctly bind to context in nested template', () => { - ɵi18nConfigureLocalize({translations: {'Item {$interpolation}': 'Article {$interpolation}'}}); + loadTranslations({'Item {$interpolation}': 'Article {$interpolation}'}); const fixture = initWithTemplate(AppComp, `
    Item {{ id }}
    @@ -248,13 +228,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should handle i18n attribute with directives', () => { - ɵi18nConfigureLocalize({translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); const fixture = initWithTemplate(AppComp, `
    Hello {{ name }}
    `); expect(fixture.nativeElement.firstChild).toHaveText('Bonjour Angular'); }); it('should work correctly with event listeners', () => { - ɵi18nConfigureLocalize({translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); @Component( {selector: 'app-comp', template: `
    Hello {{ name }}
    `}) @@ -281,14 +261,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { describe('ng-container and ng-template support', () => { it('should support ng-container', () => { - ɵi18nConfigureLocalize({translations: {'text': 'texte'}}); + loadTranslations({'text': 'texte'}); const fixture = initWithTemplate(AppComp, `text`); expect(fixture.nativeElement.innerHTML).toEqual(`texte`); }); it('should handle single translation message within ng-template', () => { - ɵi18nConfigureLocalize( - {translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); const fixture = initWithTemplate(AppComp, `Hello {{ name }}`); @@ -297,11 +276,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should be able to act as child elements inside i18n block (plain text content)', () => { - ɵi18nConfigureLocalize({ - translations: { - '{$startTagNgTemplate} Hello {$closeTagNgTemplate}{$startTagNgContainer} Bye {$closeTagNgContainer}': - '{$startTagNgTemplate} Bonjour {$closeTagNgTemplate}{$startTagNgContainer} Au revoir {$closeTagNgContainer}' - } + loadTranslations({ + + '{$startTagNgTemplate} Hello {$closeTagNgTemplate}{$startTagNgContainer} Bye {$closeTagNgContainer}': + '{$startTagNgTemplate} Bonjour {$closeTagNgTemplate}{$startTagNgContainer} Au revoir {$closeTagNgContainer}' }); const fixture = initWithTemplate(AppComp, `
    @@ -319,11 +297,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should be able to act as child elements inside i18n block (text + tags)', () => { - ɵi18nConfigureLocalize({ - translations: { - '{$startTagNgTemplate}{$startTagSpan}Hello{$closeTagSpan}{$closeTagNgTemplate}{$startTagNgContainer}{$startTagSpan}Hello{$closeTagSpan}{$closeTagNgContainer}': - '{$startTagNgTemplate}{$startTagSpan}Bonjour{$closeTagSpan}{$closeTagNgTemplate}{$startTagNgContainer}{$startTagSpan}Bonjour{$closeTagSpan}{$closeTagNgContainer}' - } + loadTranslations({ + + '{$startTagNgTemplate}{$startTagSpan}Hello{$closeTagSpan}{$closeTagNgTemplate}{$startTagNgContainer}{$startTagSpan}Hello{$closeTagSpan}{$closeTagNgContainer}': + '{$startTagNgTemplate}{$startTagSpan}Bonjour{$closeTagSpan}{$closeTagNgTemplate}{$startTagNgContainer}{$startTagSpan}Bonjour{$closeTagSpan}{$closeTagNgContainer}' }); const fixture = initWithTemplate(AppComp, `
    @@ -349,11 +326,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { const key = '{$startTagNgTemplate}Hello {$interpolation}{$closeTagNgTemplate}' + '{$startTagNgContainer}Bye {$interpolation}{$closeTagNgContainer}'; - ɵi18nConfigureLocalize({ - translations: { - [key]: - '{$startTagNgTemplate}Hej {$interpolation}{$closeTagNgTemplate}{$startTagNgContainer}Vi ses {$interpolation}{$closeTagNgContainer}' - } + loadTranslations({ + + [key]: + '{$startTagNgTemplate}Hej {$interpolation}{$closeTagNgTemplate}{$startTagNgContainer}Vi ses {$interpolation}{$closeTagNgContainer}' }); const fixture = initWithTemplate(AppComp, `
    @@ -367,11 +343,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should be able to handle deep nested levels with templates', () => { - ɵi18nConfigureLocalize({ - translations: { - '{$startTagSpan} Hello - 1 {$closeTagSpan}{$startTagSpan_1} Hello - 2 {$startTagSpan_1} Hello - 3 {$startTagSpan_1} Hello - 4 {$closeTagSpan}{$closeTagSpan}{$closeTagSpan}{$startTagSpan} Hello - 5 {$closeTagSpan}': - '{$startTagSpan} Bonjour - 1 {$closeTagSpan}{$startTagSpan_1} Bonjour - 2 {$startTagSpan_1} Bonjour - 3 {$startTagSpan_1} Bonjour - 4 {$closeTagSpan}{$closeTagSpan}{$closeTagSpan}{$startTagSpan} Bonjour - 5 {$closeTagSpan}' - } + loadTranslations({ + + '{$startTagSpan} Hello - 1 {$closeTagSpan}{$startTagSpan_1} Hello - 2 {$startTagSpan_1} Hello - 3 {$startTagSpan_1} Hello - 4 {$closeTagSpan}{$closeTagSpan}{$closeTagSpan}{$startTagSpan} Hello - 5 {$closeTagSpan}': + '{$startTagSpan} Bonjour - 1 {$closeTagSpan}{$startTagSpan_1} Bonjour - 2 {$startTagSpan_1} Bonjour - 3 {$startTagSpan_1} Bonjour - 4 {$closeTagSpan}{$closeTagSpan}{$closeTagSpan}{$startTagSpan} Bonjour - 5 {$closeTagSpan}' }); const fixture = initWithTemplate(AppComp, `
    @@ -401,11 +376,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should handle self-closing tags as content', () => { - ɵi18nConfigureLocalize({ - translations: { - '{$startTagSpan}My logo{$tagImg}{$closeTagSpan}': - '{$startTagSpan}Mon logo{$tagImg}{$closeTagSpan}' - } + loadTranslations({ + + '{$startTagSpan}My logo{$tagImg}{$closeTagSpan}': + '{$startTagSpan}Mon logo{$tagImg}{$closeTagSpan}' }); const content = `My logo`; const fixture = initWithTemplate(AppComp, ` @@ -460,11 +434,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { describe('should support ICU expressions', () => { it('with no root node', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': - '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' - } + loadTranslations({ + + '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': + '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' }); const fixture = initWithTemplate(AppComp, `{count, select, 10 {ten} 20 {twenty} other {other}}`); @@ -474,11 +447,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('with no i18n tag', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': - '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' - } + loadTranslations({ + + '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': + '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' }); const fixture = initWithTemplate( AppComp, `
    {count, select, 10 {ten} 20 {twenty} other {other}}
    `); @@ -488,12 +460,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('multiple', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}': - '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}', - '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' - } + loadTranslations({ + + '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}': + '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}', + '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' }); const fixture = initWithTemplate(AppComp, `
    {count, plural, =0 {no emails!} @@ -519,11 +490,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('with custom interpolation config', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, 10 {ten} other {{$interpolation}}}': - '{VAR_SELECT, select, 10 {dix} other {{$interpolation}}}' - } + loadTranslations({ + + '{VAR_SELECT, select, 10 {ten} other {{$interpolation}}}': + '{VAR_SELECT, select, 10 {dix} other {{$interpolation}}}' }); const interpolation = ['{%', '%}'] as[string, string]; TestBed.overrideComponent(AppComp, {set: {interpolation}}); @@ -534,12 +504,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('inside HTML elements', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}': - '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}', - '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' - } + loadTranslations({ + + '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}': + '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} {START_TAG_SPAN}emails{CLOSE_TAG_SPAN}}}', + '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' }); const fixture = initWithTemplate(AppComp, `
    {count, plural, =0 {no emails!} @@ -567,10 +536,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('inside template directives', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' - } + loadTranslations({ + + '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' }); const fixture = initWithTemplate(AppComp, `
    {name, select, other {({{name}})} @@ -588,10 +556,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('inside ng-container', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' - } + loadTranslations({ + + '{VAR_SELECT, select, other {(name)}}': '{VAR_SELECT, select, other {({$interpolation})}}' }); const fixture = initWithTemplate(AppComp, `{name, select, other {({{name}})} @@ -600,11 +567,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('inside ', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': - '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' - } + loadTranslations({ + + '{VAR_SELECT, select, 10 {ten} 20 {twenty} other {other}}': + '{VAR_SELECT, select, 10 {dix} 20 {vingt} other {autre}}' }); const fixture = initWithTemplate( AppComp, ` @@ -618,11 +584,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('nested', () => { - ɵi18nConfigureLocalize({ - translations: { - '{VAR_PLURAL, plural, =0 {zero} other {{INTERPOLATION} {VAR_SELECT, select, cat {cats} dog {dogs} other {animals}}!}}': - '{VAR_PLURAL, plural, =0 {zero} other {{INTERPOLATION} {VAR_SELECT, select, cat {chats} dog {chients} other {animaux}}!}}' - } + loadTranslations({ + + '{VAR_PLURAL, plural, =0 {zero} other {{INTERPOLATION} {VAR_SELECT, select, cat {cats} dog {dogs} other {animals}}!}}': + '{VAR_PLURAL, plural, =0 {zero} other {{INTERPOLATION} {VAR_SELECT, select, cat {chats} dog {chients} other {animaux}}!}}' }); const fixture = initWithTemplate(AppComp, `
    {count, plural, =0 {zero} @@ -647,7 +612,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { const translation = '{VAR_PLURAL, plural, =0 {zero} =2 {{INTERPOLATION} {VAR_SELECT, select, ' + 'cat {chats} dog {chients} other {animaux}}!} other {other - {INTERPOLATION}}}'; - ɵi18nConfigureLocalize({translations: {[key]: translation}}); + loadTranslations({[key]: translation}); const fixture = initWithTemplate(AppComp, `
    {count, plural, =0 {zero} @@ -729,7 +694,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { value = 3; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({translations: {}}); + loadTranslations({}); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -979,14 +944,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { describe('should support attributes', () => { it('text', () => { - ɵi18nConfigureLocalize({translations: {'text': 'texte'}}); + loadTranslations({'text': 'texte'}); const fixture = initWithTemplate(AppComp, `
    `); expect(fixture.nativeElement.innerHTML).toEqual(`
    `); }); it('interpolations', () => { - ɵi18nConfigureLocalize( - {translations: {'hello {$interpolation}': 'bonjour {$interpolation}'}}); + loadTranslations({'hello {$interpolation}': 'bonjour {$interpolation}'}); const fixture = initWithTemplate(AppComp, `
    `); expect(fixture.nativeElement.innerHTML).toEqual(`
    `); @@ -997,16 +961,14 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('with pipes', () => { - ɵi18nConfigureLocalize( - {translations: {'hello {$interpolation}': 'bonjour {$interpolation}'}}); + loadTranslations({'hello {$interpolation}': 'bonjour {$interpolation}'}); const fixture = initWithTemplate( AppComp, `
    `); expect(fixture.nativeElement.innerHTML).toEqual(`
    `); }); it('multiple attributes', () => { - ɵi18nConfigureLocalize( - {translations: {'hello {$interpolation}': 'bonjour {$interpolation}'}}); + loadTranslations({'hello {$interpolation}': 'bonjour {$interpolation}'}); const fixture = initWithTemplate( AppComp, ``); @@ -1020,16 +982,14 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('on removed elements', () => { - ɵi18nConfigureLocalize( - {translations: {'text': 'texte', '{$startTagSpan}content{$closeTagSpan}': 'contenu'}}); + loadTranslations({'text': 'texte', '{$startTagSpan}content{$closeTagSpan}': 'contenu'}); const fixture = initWithTemplate(AppComp, `
    content
    `); expect(fixture.nativeElement.innerHTML).toEqual(`
    contenu
    `); }); it('with custom interpolation config', () => { - ɵi18nConfigureLocalize( - {translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); const interpolation = ['{%', '%}'] as[string, string]; TestBed.overrideComponent(AppComp, {set: {interpolation}}); const fixture = @@ -1040,7 +1000,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('in nested template', () => { - ɵi18nConfigureLocalize({translations: {'Item {$interpolation}': 'Article {$interpolation}'}}); + loadTranslations({'Item {$interpolation}': 'Article {$interpolation}'}); const fixture = initWithTemplate(AppComp, `
    @@ -1054,8 +1014,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should add i18n attributes on self-closing tags', () => { - ɵi18nConfigureLocalize( - {translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}'}}); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}'}); const fixture = initWithTemplate(AppComp, ``); @@ -1128,15 +1087,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [ClsDir, MyApp]}); - ɵi18nConfigureLocalize({ - translations: { - // Not that this translation switches the order of the expressions! - 'start {$interpolation} middle {$interpolation_1} end': - 'début {$interpolation_1} milieu {$interpolation} fin', - '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} emails}}': - '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} emails}}', - ' trad: {$icu} ': ' traduction: {$icu} ' - } + loadTranslations({ + // Not that this translation switches the order of the expressions! + 'start {$interpolation} middle {$interpolation_1} end': + 'début {$interpolation_1} milieu {$interpolation} fin', + '{VAR_PLURAL, plural, =0 {no {START_BOLD_TEXT}emails{CLOSE_BOLD_TEXT}!} =1 {one {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} emails}}': + '{VAR_PLURAL, plural, =0 {aucun {START_BOLD_TEXT}email{CLOSE_BOLD_TEXT}!} =1 {un {START_ITALIC_TEXT}email{CLOSE_ITALIC_TEXT}} other {{INTERPOLATION} emails}}', + ' trad: {$icu} ': ' traduction: {$icu} ' }); const fixture = TestBed.createComponent(MyApp); fixture.detectChanges(); @@ -1178,9 +1135,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [AppComp, MyComp]}); - ɵi18nConfigureLocalize({ - translations: {'Hello {$interpolation}': 'Bonjour {$interpolation}', 'works': 'fonctionne'} - }); + loadTranslations({'Hello {$interpolation}': 'Bonjour {$interpolation}', 'works': 'fonctionne'}); const fixture = initWithTemplate( AppComp, ``); @@ -1194,11 +1149,9 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); it('should support adding/moving/removing nodes', () => { - ɵi18nConfigureLocalize({ - translations: { - '{$startTagDiv2}{$closeTagDiv2}{$startTagDiv3}{$closeTagDiv3}{$startTagDiv4}{$closeTagDiv4}{$startTagDiv5}{$closeTagDiv5}{$startTagDiv6}{$closeTagDiv6}{$startTagDiv7}{$closeTagDiv7}{$startTagDiv8}{$closeTagDiv8}': - '{$startTagDiv2}{$closeTagDiv2}{$startTagDiv8}{$closeTagDiv8}{$startTagDiv4}{$closeTagDiv4}{$startTagDiv5}{$closeTagDiv5}Bonjour monde{$startTagDiv3}{$closeTagDiv3}{$startTagDiv7}{$closeTagDiv7}' - } + loadTranslations({ + '{$startTagDiv2}{$closeTagDiv2}{$startTagDiv3}{$closeTagDiv3}{$startTagDiv4}{$closeTagDiv4}{$startTagDiv5}{$closeTagDiv5}{$startTagDiv6}{$closeTagDiv6}{$startTagDiv7}{$closeTagDiv7}{$startTagDiv8}{$closeTagDiv8}': + '{$startTagDiv2}{$closeTagDiv2}{$startTagDiv8}{$closeTagDiv8}{$startTagDiv4}{$closeTagDiv4}{$startTagDiv5}{$closeTagDiv5}Bonjour monde{$startTagDiv3}{$closeTagDiv3}{$startTagDiv7}{$closeTagDiv7}' }); const fixture = initWithTemplate(AppComp, `
    @@ -1236,12 +1189,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Child of {$interpolation}': 'Enfant de {$interpolation}', - '{$startTagChild}I am projected from {$startBoldText}{$interpolation}{$startTagRemoveMe_1}{$closeTagRemoveMe_1}{$closeBoldText}{$startTagRemoveMe_2}{$closeTagRemoveMe_2}{$closeTagChild}{$startTagRemoveMe_3}{$closeTagRemoveMe_3}': - '{$startTagChild}Je suis projeté depuis {$startBoldText}{$interpolation}{$closeBoldText}{$closeTagChild}' - } + loadTranslations({ + + 'Child of {$interpolation}': 'Enfant de {$interpolation}', + '{$startTagChild}I am projected from {$startBoldText}{$interpolation}{$startTagRemoveMe_1}{$closeTagRemoveMe_1}{$closeBoldText}{$startTagRemoveMe_2}{$closeTagRemoveMe_2}{$closeTagChild}{$startTagRemoveMe_3}{$closeTagRemoveMe_3}': + '{$startTagChild}Je suis projeté depuis {$startBoldText}{$interpolation}{$closeBoldText}{$closeTagChild}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1270,11 +1222,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Child of {$interpolation}': 'Enfant de {$interpolation}', - 'I am projected from {$interpolation}': 'Je suis projeté depuis {$interpolation}' - } + loadTranslations({ + + 'Child of {$interpolation}': 'Enfant de {$interpolation}', + 'I am projected from {$interpolation}': 'Je suis projeté depuis {$interpolation}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1313,11 +1264,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [Parent, Child, GrandChild]}); - ɵi18nConfigureLocalize({ - translations: { - '{$startBoldText}Hello{$closeBoldText} World!': - '{$startBoldText}Bonjour{$closeBoldText} monde!' - } + loadTranslations({ + + '{$startBoldText}Hello{$closeBoldText} World!': + '{$startBoldText}Bonjour{$closeBoldText} monde!' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1341,8 +1291,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [Parent, Child, GrandChild]}); - ɵi18nConfigureLocalize( - {translations: {'{$startBoldText}Hello{$closeBoldText} World!': 'Bonjour monde!'}}); + loadTranslations({'{$startBoldText}Hello{$closeBoldText} World!': 'Bonjour monde!'}); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); expect(fixture.nativeElement.innerHTML) @@ -1367,11 +1316,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - '{$startTagSpan}{$closeTagSpan}{$startTagSpan_1}{$closeTagSpan}': - '{$startTagSpan}Contenu{$closeTagSpan}' - } + loadTranslations({ + + '{$startTagSpan}{$closeTagSpan}{$startTagSpan_1}{$closeTagSpan}': + '{$startTagSpan}Contenu{$closeTagSpan}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1392,11 +1340,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Content projected from {$startTagNgContent}{$closeTagNgContent}': - 'Contenu projeté depuis {$startTagNgContent}{$closeTagNgContent}' - } + loadTranslations({ + + 'Content projected from {$startTagNgContent}{$closeTagNgContent}': + 'Contenu projeté depuis {$startTagNgContent}{$closeTagNgContent}' }); const fixture = TestBed.createComponent(Parent); @@ -1423,11 +1370,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Content projected from {$startTagNgContent}{$closeTagNgContent}': - '{$startTagNgContent}{$closeTagNgContent} a projeté le contenu' - } + loadTranslations({ + + 'Content projected from {$startTagNgContent}{$closeTagNgContent}': + '{$startTagNgContent}{$closeTagNgContent} a projeté le contenu' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1446,12 +1392,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Child content {$startTagNgContent}{$closeTagNgContent}': - 'Contenu enfant {$startTagNgContent}{$closeTagNgContent}', - 'and projection from {$interpolation}': 'et projection depuis {$interpolation}' - } + loadTranslations({ + + 'Child content {$startTagNgContent}{$closeTagNgContent}': + 'Contenu enfant {$startTagNgContent}{$closeTagNgContent}', + 'and projection from {$interpolation}': 'et projection depuis {$interpolation}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1478,7 +1423,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { value = 3; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({translations: {}}); + loadTranslations({}); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1501,12 +1446,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Child content {$startTagNgContent}{$closeTagNgContent}': - 'Contenu enfant {$startTagNgContent}{$closeTagNgContent}', - 'and projection from {$icu}': 'et projection depuis {$icu}' - } + loadTranslations({ + + 'Child content {$startTagNgContent}{$closeTagNgContent}': + 'Contenu enfant {$startTagNgContent}{$closeTagNgContent}', + 'and projection from {$icu}': 'et projection depuis {$icu}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1532,11 +1476,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { name: string = 'Parent'; } TestBed.configureTestingModule({declarations: [Parent, Child]}); - ɵi18nConfigureLocalize({ - translations: { - 'Child content {$startTagNgContent}{$closeTagNgContent}': 'Contenu enfant', - 'and projection from {$interpolation}': 'et projection depuis {$interpolation}' - } + loadTranslations({ + + 'Child content {$startTagNgContent}{$closeTagNgContent}': 'Contenu enfant', + 'and projection from {$interpolation}': 'et projection depuis {$interpolation}' }); const fixture = TestBed.createComponent(Parent); fixture.detectChanges(); @@ -1622,11 +1565,10 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { } TestBed.configureTestingModule({declarations: [TextDirective, DivQuery]}); - ɵi18nConfigureLocalize({ - translations: { - '{$startTagNgTemplate}{$startTagDiv_1}{$startTagDiv}{$startTagSpan}Content{$closeTagSpan}{$closeTagDiv}{$closeTagDiv}{$closeTagNgTemplate}': - '{$startTagNgTemplate}Contenu{$closeTagNgTemplate}' - } + loadTranslations({ + + '{$startTagNgTemplate}{$startTagDiv_1}{$startTagDiv}{$startTagSpan}Content{$closeTagSpan}{$closeTagDiv}{$closeTagDiv}{$closeTagNgTemplate}': + '{$startTagNgTemplate}Contenu{$closeTagNgTemplate}' }); const fixture = initWithTemplate(AppComp, ` diff --git a/packages/core/test/acceptance/view_container_ref_spec.ts b/packages/core/test/acceptance/view_container_ref_spec.ts index b73e2c26f5..a210dc3225 100644 --- a/packages/core/test/acceptance/view_container_ref_spec.ts +++ b/packages/core/test/acceptance/view_container_ref_spec.ts @@ -7,10 +7,11 @@ */ import {CommonModule, DOCUMENT} from '@angular/common'; -import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, RendererType2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ɵi18nConfigureLocalize} from '@angular/core'; +import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, RendererType2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core'; import {Input} from '@angular/core/src/metadata'; import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode'; import {TestBed, TestComponentRenderer} from '@angular/core/testing'; +import {loadTranslations} from '@angular/localize/run_time'; import {By, DomSanitizer} from '@angular/platform-browser'; import {expect} from '@angular/platform-browser/testing/src/matchers'; import {ivyEnabled, onlyInIvy} from '@angular/private/testing'; @@ -35,7 +36,7 @@ describe('ViewContainerRef', () => { } beforeEach(() => { - ɵi18nConfigureLocalize({translations: TRANSLATIONS}); + loadTranslations(TRANSLATIONS); TestBed.configureTestingModule({ declarations: [ StructDir, ViewContainerRefComp, ViewContainerRefApp, DestroyCasesComp, ConstructorDir, diff --git a/packages/core/test/bundling/hello_world_i18n/BUILD.bazel b/packages/core/test/bundling/hello_world_i18n/BUILD.bazel index c664a93dd8..acd83c5928 100644 --- a/packages/core/test/bundling/hello_world_i18n/BUILD.bazel +++ b/packages/core/test/bundling/hello_world_i18n/BUILD.bazel @@ -5,9 +5,13 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "http_server") ng_module( name = "hello_world_i18n", - srcs = ["index.ts"], + srcs = [ + "index.ts", + "translations.ts", + ], deps = [ "//packages/core", + "//packages/localize/run_time", ], ) diff --git a/packages/core/test/bundling/hello_world_i18n/index.ts b/packages/core/test/bundling/hello_world_i18n/index.ts index f6391126ba..c9d3349ca0 100644 --- a/packages/core/test/bundling/hello_world_i18n/index.ts +++ b/packages/core/test/bundling/hello_world_i18n/index.ts @@ -5,15 +5,8 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ - -import {Component, NgModule, ɵi18nConfigureLocalize, ɵrenderComponent as renderComponent} from '@angular/core'; - -const translations = { - 'Hello World!': 'Bonjour Monde!', - 'Hello Title!': 'Bonjour Titre!', -}; - -ɵi18nConfigureLocalize({translations}); +import './translations'; +import {Component, NgModule, ɵrenderComponent as renderComponent} from '@angular/core'; @Component({ selector: 'hello-world', diff --git a/packages/core/test/bundling/hello_world_i18n/translations.ts b/packages/core/test/bundling/hello_world_i18n/translations.ts new file mode 100644 index 0000000000..7d1fb21f54 --- /dev/null +++ b/packages/core/test/bundling/hello_world_i18n/translations.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {loadTranslations} from '@angular/localize/run_time'; + +const translations = { + 'Hello World!': 'Bonjour Monde!', + 'Hello Title!': 'Bonjour Titre!', +}; + +loadTranslations(translations); diff --git a/packages/core/test/bundling/todo_i18n/BUILD.bazel b/packages/core/test/bundling/todo_i18n/BUILD.bazel index a45ef64f2f..21d5ac8664 100644 --- a/packages/core/test/bundling/todo_i18n/BUILD.bazel +++ b/packages/core/test/bundling/todo_i18n/BUILD.bazel @@ -17,7 +17,7 @@ ng_module( "//packages/common", "//packages/core", "//packages/core/test/bundling/util:reflect_metadata", - "//packages/localize", + "//packages/localize/run_time", ], ) diff --git a/packages/core/test/bundling/todo_i18n/index.ts b/packages/core/test/bundling/todo_i18n/index.ts index 627e14961d..609c372562 100644 --- a/packages/core/test/bundling/todo_i18n/index.ts +++ b/packages/core/test/bundling/todo_i18n/index.ts @@ -9,13 +9,6 @@ import '@angular/core/test/bundling/util/src/reflect_metadata'; // Make the `$localize()` global function available to the compiled templates, and the direct calls // below. This would normally be done inside the application `polyfills.ts` file. import '@angular/localize'; -/** - * TODO(ocombe): replace this with the real runtime i18n service configuration - * For now we define inline translations that are added with the function `ɵi18nConfigureLocalize`, - * but this function will go away once we have finished designing and implementing the new runtime - * service. At this point we should revisit this code and update it to use that new service. - * See FW-114. - */ import './translations'; import {CommonModule} from '@angular/common'; import {Component, Injectable, NgModule, ViewEncapsulation, ɵmarkDirty as markDirty, ɵrenderComponent as renderComponent} from '@angular/core'; diff --git a/packages/core/test/bundling/todo_i18n/translations.ts b/packages/core/test/bundling/todo_i18n/translations.ts index 9fa77c6744..fa79645d3c 100644 --- a/packages/core/test/bundling/todo_i18n/translations.ts +++ b/packages/core/test/bundling/todo_i18n/translations.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {ɵi18nConfigureLocalize} from '@angular/core'; +import {loadTranslations} from '@angular/localize/run_time'; -export const translations: {[key: string]: string} = { +export const translations = { 'What needs to be done?': `Qu'y a-t-il à faire ?`, '{$startHeadingLevel1}todos{$closeHeadingLevel1}{$tagInput}': '{$startHeadingLevel1}liste de tâches{$closeHeadingLevel1}{$tagInput}', @@ -24,4 +24,4 @@ export const translations: {[key: string]: string} = { 'Demonstrate internationalization': `Démontrer l'internationalisation` }; -ɵi18nConfigureLocalize({translations}); +loadTranslations(translations);