i18n: Adding new languages: Part 1 (#1882)

Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
José Alberto Hernández
2023-10-22 20:18:05 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent c7fe21e74a
commit 408f004450
432 changed files with 38051 additions and 44613 deletions
+25 -17
View File
@@ -13,7 +13,7 @@ Use the `translate` directive on an HTML element to automatically translate its
You can also use the `translate` pipe if needed:
```html
<button title="{{ 'Add item' | translate }}">+</button>
<button title="{{'Add item' | translate}}">+</button>
```
### In TypeScript code
@@ -26,28 +26,36 @@ let title;
translateService.get('My page title').subscribe((res: string) => { title = res; });
```
or `TranslateService` dependency and use the asynchronous
`instant()` method:
```typescript
const title: string = translateService.instant('My page title');
```
## Extracting strings to translate
Once you are ready to translate your app, just run `npm translations:extract`.
It will create a `template.json` file in the `src/translations` folder.
It will create a `template.json` file in the `src/assets/translations` folder.
You can then use any text or code editor to generate the `.json` files for each of your supported languages, and put
them in the `src/translations` folder.
them in the `src/assets/translations` folder.
Do no forget to edit the files in `src/environment` to add the supported languages of your application.
### Marking strings for extraction
These are the Language available now:
If strings are not directly passed to `translateService` or put in HTML templates, they may be missing from the
extraction process.
For these cases, you have to use the dummy `extract()` function:
```typescript
import { extract } from './core/i18n.service';
function toBeTranslatedLater() {
return extract('A string to be translated');
}
```
Strings marked like this will then be properly extracted.
| Language | Code | File |
|:----------:|:----:|:----------:|
| Czech | cs | cs-CS.json |
| German | de | de-DE.json |
| English | en | en-US.json |
| Spanish | es | es-MX.json |
| French | fr | fr-FR.json |
| Italian | it | it-IT.json |
| Korean | ko | ko-KO.json |
| Lithuanian | li | li-LI.json |
| Latvian | lv | lv-LV.json |
| Nepali | ne | ne-NE.json |
| Portuguese | pt | pt-PT.json |
| Swahili | sw | sw-SW.json |