Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

docs(i18n): add internationalization (i18n) guide #2491

Merged
merged 2 commits into from
Sep 29, 2016

Conversation

wardbell
Copy link
Contributor

Ward's edited review of the @ocombe, @Foxandxss, @filipesilva original based on PR #2340.

Re-branched in case someone needs to go back to the unsquashed #2340

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@ghost
Copy link

ghost commented Sep 27, 2016

Very happy that documentation will be added :)
Maybe it's good to also discuss the following things:

  1. What about changing language at run time? The documentation only describes how to do it at bootstrap time.
  2. Tokens in a translation? E.g. I've got error messages saying "You've got {{n}} errors". I can't split that in 2 translations "You've got" and "errors" as in other languages the order of words in a sentence is different.

It could be that it's being worked on, but for clarity it's good to highlight that.

@wardbell
Copy link
Contributor Author

@rolandoldengarm This is a minimum, introductory chapter. We'll be revising as more i18n features and ergonomics arrive. Thanks for the feedback though.

@wardbell wardbell force-pushed the docs-i18n-guide branch 4 times, most recently from a5b8267 to ed95dab Compare September 29, 2016 00:10
@wardbell wardbell force-pushed the docs-i18n-guide branch 2 times, most recently from 27032d3 to 0b6443f Compare September 29, 2016 11:25
@wardbell
Copy link
Contributor Author

wardbell commented Sep 29, 2016

@rolandoldengarm Almost ready with this PR.

Quick answers to your questions:

  1. This PR will mention that you cannot change the language dynamically. You must re-load the web page. That's because the language-substitution happens as a compile step, not as the app runs.

This makes sense to me. The facility described here is for static content in the component templates, not live content from a database. Therefore, there is no obvious benefit to re-translating fixed text for every component as it loads. That would make the page slower and heavier.

It seems also a safe bet that users aren't changing language in the middle of their work. A page re-load at the start (if you loaded the wrong version), is a small price for smooth running throughout the session.

  1. There is a separate facility, not yet documented, for handling pluralization: i18nPluralPipe. Please give it a try. If you have an issue, please file that on the angular site, not here!

Cheers.

@wardbell wardbell merged commit e6199a8 into angular:master Sep 29, 2016
@wardbell wardbell deleted the docs-i18n-guide branch September 29, 2016 18:15
const noProviders: Object[] = [];

// No locale or English: no translation providers
if (!locale || locale === 'en') {
Copy link
Contributor

Choose a reason for hiding this comment

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

en-US

include ../_util-fns

:marked
Angular's _internationalization_ ("_i18n_") tools help make your app availble in multiple languages.
Copy link
Contributor

Choose a reason for hiding this comment

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

available


.alert.is-helpful
:marked
`i18n` is not an Angular _directive_. It's a custom _attribute_, recognized by Angular tools and compilers.
Copy link
Contributor

Choose a reason for hiding this comment

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

it gets remove at compile time
(this is actually only true when a i18n file is provided to ngc for now but eventually it will always)

While all appearance of a message with the _same_ meaning should have the _same_ translation,
a message with *different meanings* could have different translations.
The Angular extraction tool preserves both the _meaning_ and the _description_ in the translation source file
to facilitiate contextually-specific transations.
Copy link
Contributor

Choose a reason for hiding this comment

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

translations


Use the `ng-xi18n` extraction tool to generate a translation source file in an industry standard format.

This is an Angular CLI tool based on the `ngc` compiler in the `@angular/compiler-cli` npm package.
Copy link
Contributor

Choose a reason for hiding this comment

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

again I don't see the need to mention ngc here

a#translate
.l-main-section
:marked
## Translate _le message textuel_
Copy link
Contributor

Choose a reason for hiding this comment

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

"le message textuel" reminds me of my english :)

You will probably translate into more than one other language so it's a good idea
for the project structure to reflect your entire internationalization effort.

One approach is to create an `i18n` folder with subfolders for each language or locale, e.g. `i18n/fr` for French.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think 'locale/messages.fr.xlf` is more "standard"

+makeExample('cb-i18n/ts/i18n/fr/messages.fr.xlf.html', 'trans-unit', 'i18n/fr/messages.fr.xlf (<trans-unit>, after translation)')(format=".")
:marked
Note that the `id` is generated by the tool. Don't touch it.
Its value depends on the content of the message, its meaning, and its description.
Copy link
Contributor

Choose a reason for hiding this comment

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

not the description, only text + meaning

@ghost
Copy link

ghost commented Sep 30, 2016

@wardbell Thank you very much, appreciate your reply! Reloading app is no problem, and for my other issue there seems to be a solution as well.
I've got one more issue with the documentation: Is there a translation service to grab messages from my TS code? I.e. something like i18nService.getTranslation("...") ?

@vicb
Copy link
Contributor

vicb commented Sep 30, 2016

I've got one more issue with the documentation: Is there a translation service to grab messages from my TS code? I.e. something like i18nService.getTranslation("...") ?

not yet. you can up vote angular/angular#11405

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

Successfully merging this pull request may close these issues.

4 participants