Skip to content

Instantly share code, notes, and snippets.

@guilnorth
Last active October 19, 2022 22:09
Show Gist options
  • Save guilnorth/6c82c17a1ac59262d19ce9fb199b7880 to your computer and use it in GitHub Desktop.
Save guilnorth/6c82c17a1ac59262d19ce9fb199b7880 to your computer and use it in GitHub Desktop.
App exemplo PO-UI Language #1457
<po-page-default p-title="PO UI">
<po-select
class="po-md-3"
name="locales"
[ngModel]="locale"
(ngModelChange)="locale = $event; onChangeLocale();"
p-label="Localization Example"
[p-options]="localesOptions"
>
</po-select>
{{title}}
</po-page-default>
import { Component, OnInit, VERSION } from '@angular/core';
import { PoI18nService } from '../../../ui/src/lib';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
locale: string;
title: string;
localesOptions = [
{ label: 'Português Brasileiro', value: 'pt-br' },
{ label: 'Russo', value: 'ru-ru' },
];
constructor(private _poI18nService: PoI18nService) {}
ngOnInit(): void {
this.locale = this._poI18nService.getLanguage();
this._poI18nService.getLiterals().subscribe((literals) => {
this.title = literals['title'];
});
}
onChangeLocale() {
if (this.locale) this._poI18nService.setLanguage(this.locale, true);
}
}
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { PoModule } from '@po-ui/ng-components';
import { AppComponent } from './app.component';
import { PoI18nConfig, PoI18nModule } from '../../../ui/src/lib';
const generalPt = {
title: 'Título do texto'
};
export const generalRu = {
title: 'Текстовое название'
};
const i18nConfig: PoI18nConfig = {
default: {
language: 'ru-ru', // deve respeitar a configuração default, independente do resetAfterReload
},
contexts: {
general: {
'pt-BR': generalPt,
'ru-RU': generalRu,
},
},
resetAfterReload: true
};
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
FormsModule, RouterModule.forRoot([],
{ relativeLinkResolution: 'legacy' }),
PoModule,
PoI18nModule.config(i18nConfig),],
bootstrap: [AppComponent]
})
export class AppModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment