Other Articles in the Series
- Overview
- Add new Permission
- Project structure
- Multi-Languages (i18n)
- DI & IoC - Why and Why not?
- RESTful & WebApi
- Manage Application Lifecycle
- Build & Deploy Application
- New version of TinyERP with Angular 2 (typescript)
- CQRS: Avoiding performance issues in enterprise app (basic)
- Multiple data-stores: Scale your repository (Part 1)
- Multiple data-stores: Scale your repository (Part 2)
- Basic authentication (user name/ password) with OWIN
Introduction
I have looked around the internet. Some others have already contributed their solution for multi-languages in Angular2.
Look at my code. I have another solution for this case, it looks easier to use on both ts code or from html file.
How to Get the Code
Please check out the code at https://github.com/techcoaching/TinyERP.
How to Use the Code
Look at "<root>/app/modules/security/role/addRole.html", we see the following HTML:
<page>
<page-header>
{{i18n.security.addOrUpdateRole.title}}
</page-header>
<page-content>
<form-default>
<form-text-input [placeHolderText]=i18n.security.addOrUpdateRole.inputName
[labelText]=i18n.security.addOrUpdateRole.name
[validation]="['security.addOrUpdateRole.validation.nameIsRequire',
'security.addOrUpdateRole.validation.keyAlreadyExisted']"
[(model)]=model.name>
</form-text-input>
<form-textarea [placeHolderText]=i18n.security.addOrUpdateRole.inputDesc
[labelText]=i18n.security.addOrUpdateRole.desc [(model)]=model.description>
</form-textarea>
<form-permission-select [(values)]=model.permissions
[placeHolderText]=i18n.security.addOrUpdateRole.inputPermissions
[labelText]=i18n.security.addOrUpdateRole.permission
[(model)]=model.permissions>
</form-permission-select>
<form-footer>
<button id="save"
(click)="onSaveClicked($event)" type="button"
class="btn btn-primary">{{i18n.common.form.save}}</button>
<button id="cancel"
(click)="onCancelClicked($event)" type="button"
class="btn btn-default">{{i18n.common.form.cancel}}</button>
</form-footer>
</form-default>
</page-content>
</page>
In this HTML, we use some texts from locale file, such as: i18n.security.addOrUpdateRole.inputName
, i18n.security.addOrUpdateRole.name
, ...
There is a convention for those texts, they are in format: i18n.<moduleName>.<name of page>.<name of field>
. For example, "i18n.security.addOrUpdateRole.name
", we understand that this is the text for name field on addOrUpdateRole
page in security module.
For a better understanding about moduleName
, see Angular2 & WebApi(SPA) for Enterprise App - Part 3 - Project Structure.
The value for those was located in "<root>/app/resosurces/locales/<moduleName>.<language>.json", for example security.en.json will contain all text that was used in security module in English language.
For more information, how did I implement this, please have a look at "<root>/app/models/ui/baseComponent.ts" (for i18nHelper
and i18n
properties).
Other Articles in the Series
- Single Page Application (SPA) for Enterprise App (Angular2 & WebApi)
- Single Page Application (SPA) for Enterprise App (Angular2 & WebApi) - Part 2
- Angular2 & WebApi (SPA) for Enterprise App - Part 3 - Project structure
Introduction
I have looked around the internet. Some others have already contributed their solution for multi-languages in Angular2.
Look at my code. I have another solution for this case, it looks easier to use on both ts code or from html file.
How to Get the Code
Please check out the code at https://github.com/techcoaching/TinyERP.
How to Use the Code
Look at "<root>/app/modules/security/role/addRole.html", we see the following HTML:
<page>
<page-header>
{{i18n.security.addOrUpdateRole.title}}
</page-header>
<page-content>
<form-default>
<form-text-input [placeHolderText]=i18n.security.addOrUpdateRole.inputName
[labelText]=i18n.security.addOrUpdateRole.name
[validation]="['security.addOrUpdateRole.validation.nameIsRequire',
'security.addOrUpdateRole.validation.keyAlreadyExisted']"
[(model)]=model.name>
</form-text-input>
<form-textarea [placeHolderText]=i18n.security.addOrUpdateRole.inputDesc
[labelText]=i18n.security.addOrUpdateRole.desc [(model)]=model.description>
</form-textarea>
<form-permission-select [(values)]=model.permissions
[placeHolderText]=i18n.security.addOrUpdateRole.inputPermissions
[labelText]=i18n.security.addOrUpdateRole.permission
[(model)]=model.permissions>
</form-permission-select>
<form-footer>
<button id="save"
(click)="onSaveClicked($event)" type="button"
class="btn btn-primary">{{i18n.common.form.save}}</button>
<button id="cancel"
(click)="onCancelClicked($event)" type="button"
class="btn btn-default">{{i18n.common.form.cancel}}</button>
</form-footer>
</form-default>
</page-content>
</page>
In this HTML, we use some texts from locale file, such as: i18n.security.addOrUpdateRole.inputName
, i18n.security.addOrUpdateRole.name
, ...
There is a convention for those texts, they are in format: i18n.<moduleName>.<name of page>.<name of field>
. For example, "i18n.security.addOrUpdateRole.name
", we understand that this is the text for name field on addOrUpdateRole
page in security module.
For a better understanding about moduleName
, see Angular2 & WebApi(SPA) for Enterprise App - Part 3 - Project Structure.
The value for those was located in "<root>/app/resosurces/locales/<moduleName>.<language>.json", for example security.en.json will contain all text that was used in security module in English language.
For more information, how did I implement this, please have a look at "<root>/app/models/ui/baseComponent.ts" (for i18nHelper
and i18n
properties).
For more information about: