OTranslateService
For translations, Ontimize Web use OTranslateService
which is a service and a pipe to handle any dynamic and static content you can help you make your app available in multiples languages.
Define the translations
Once you’ve installed ontimize-web-ngx
, you can put your translations in a json file (locale_id.json) in src/assets/i18n
folder. There must be at least one language translation file for the resulting translation. OTranslateService
understands nested JSON objects.
{
"HOME": {
"HELLO": "hello"
}
}
You can then access the value by using the dot notation, in this case HOME.HELLO.
Init the OTranslateService for your application.
import { Subscription } from 'rxjs';
import { Component } from '@angular/core';
import { OTranslateService } from "ontimize-web-ngx";
@Component({
selector: 'app',
template: `
...
`
})
export class AppComponent {
private translateServiceSubscription :Subscription;
constructor(translate: OTranslateService) {
this.translateServiceSubscription = this.translateService.onLanguageChanged.subscribe(() => {
// your code
});
});
public ngOnDestroy(): void {
if (this.translateServiceSubscription) {
this.translateServiceSubscription.unsubscribe();
}
}
}
Having the following entry in the bundle file:
{
...
"EXAMPLE": "Example bundle text: {0}, {1}",
...
}
User can add in the html file:
{{ 'EXAMPLE' | oTranslate : { values: ['foo', 'bar'] }}}"
And get the following result:
'Example bundle text: foo, bar'
OTranslateService
Class: OTranslateService
Inputs
Name | Description | Default |
---|---|---|
columns string |
Entity columns. Separated by ‘;’ |
|
description-columns string |
Visible columns in text field |
|
entity string |
Service entity name |
|
parent-keys string |
Filtering keys. Separated by ‘;’. It is possible to use alias on the following way: compCol1:fk1;compCol2:fk2 where compCol1 and compCol2 are component columns and fk1 and fk2 are attributes from form fields. It is also possible to define a column next to the alias for getting that column value instead of the component value: compCol1:fk1[fkCol] |
|
query-method string |
Service method name for queries |
query |
query-on-bind no | false | yes | true |
Query table data on bind |
|
query-on-event |
A component event reference the component must listen to in order to perform its query |
|
query-on-init no | false | yes | true |
Query table data on init |
yes |
query-with-null-parent-keys no | false | yes | true |
Indicates whether or not to trigger query method when the filter generated from parent-keys is null. The use of this attribute is not recommended when the component may request a big amount of information |
no |
separator string |
Separation character between |
|
service string |
JEE service path |
|
service-type string |
Injection token indicated in the provider of the service |
|
set-value-on-value-change string |
Form component attributes whose value will be set when the value of the current component changes due to user interaction. Separated by ‘;’. Accepted format: |
|
static-data array |
Static data for filling the table |
|
value-column string |
Column of the entity from where the component will get its value |
|
value-column-type string |
|
int |
visible-columns string |
Visible columns. Separated by ‘;’ |
|
Outputs
Name | Description |
---|---|
onLanguageChanged |
Event triggered when the lang change events |
Methods
get |
---|
Gets the translated value of a key or the key if the value was not found |
Parameters |
text: string, values: any[] |
getBrowserLang |
---|
Returns the current browser lang if available. |
getCurrentLang |
---|
Returns the lang currently used. |
setAppLang |
---|
Parameters |
lang: string |
setDefaultLang |
---|
Sets the default language to use as a fallback |
Parameters |
lang: string |
use |
---|
Parameters |
lang: string, observer?: Subscriber |