Skip to content

Commit

Permalink
Add i18n documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Nov 9, 2020
1 parent 6c8aff5 commit e14da72
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/showcase/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { HomeComponent } from './components/home/home.component';
{path: 'inputtext', loadChildren: () => import('./components/inputtext/inputtextdemo.module').then(m => m.InputTextDemoModule)},
{path: 'inputgroup', loadChildren: () => import('./components/inputgroup/inputgroupdemo.module').then(m => m.InputGroupDemoModule)},
{path: 'inputtextarea', loadChildren: () => import('./components/inputtextarea/inputtextareademo.module').then(m => m.InputTextareaDemoModule)},
{path: 'i18n', loadChildren: () => import('./components/i18n/i18n.module').then(m => m.I18NModule)},
{path: 'keyfilter', loadChildren: () => import('./components/keyfilter/keyfilterdemo.module').then(m => m.KeyFilterDemoModule)},
{path: 'listbox', loadChildren: () => import('./components/listbox/listboxdemo.module').then(m => m.ListboxDemoModule)},
{path: 'lts', loadChildren: () => import('./components/lts/lts.module').then(m => m.LTSModule)},
Expand Down
1 change: 1 addition & 0 deletions src/app/showcase/app.menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare let gtag: Function;
<div class="menu-category">General</div>
<div class="menu-items">
<a [routerLink]=" ['/setup']" routerLinkActive="router-link-exact-active">Get Started</a>
<a [routerLink]=" ['/i18n']" routerLinkActive="router-link-exact-active">I18N</a>
<a href="https://github.com/primefaces/primeng/wiki/Migration-Guide" target="_blank">Migration Guide</a>
<a href="https://github.com/primefaces/primeng" target="_blank">Source Code</a>
<a href="https://www.primefaces.org/store">Store</a>
Expand Down
15 changes: 15 additions & 0 deletions src/app/showcase/components/i18n/i18n-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
import {I18NComponent} from './i18n.component';

@NgModule({
imports: [
RouterModule.forChild([
{path:'',component: I18NComponent}
])
],
exports: [
RouterModule
]
})
export class I18NRoutingModule {}
193 changes: 193 additions & 0 deletions src/app/showcase/components/i18n/i18n.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<div class="content-section documentation">
<h1>I18N</h1>
<p>The i18n API allows setting translations globally for the components and integration with translation libraries.</p>

<h5>PrimeNGConfig</h5>
<p>A translation is applied using the PrimeNGConfig instance so begin with injecting it. A common location is the application root to initalize the default language used by the components.
English is the default language and <i>setTranslation</i> function is used to change the values by passing a <i>Translation</i> object.</p>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123; Component, OnInit, OnDestroy &#125; from '@angular/core';
import &#123; PrimeNGConfig &#125; from 'primeng/api';

@Component(&#123;
selector: 'app-root',
templateUrl: './app.component.html'
&#125;)
export class AppComponent implements OnInit, OnDestroy &#123;

constructor(private config: PrimeNGConfig) &#123;&#125;

ngOnInit() &#123;
this.config.setTranslation(&#123;
accept: 'Accept',
reject: 'Cancel',
//translations
&#125;);
&#125;
&#125;
</app-code>

<h5>ngx-translate</h5>
<p>i18n API can easily be integrated with 3rd party libraries such as ngx-translate that even allows
dynamically changing the language in the application.</p>

<h5>en.json</h5>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
&#123;
"primeng": &#123;
"startsWith": "Starts with",
"contains": "Contains",
"notContains": "Not contains",
"endsWith": "Ends with",
"equals": "Equals",
"notEquals": "Not equals",
"lt": "Less than",
"lte": "Less than or equal to",
"gt": "Greater than",
"gte": "Great then or equals",
"is": "Is",
"isNot": "Is not",
"before": "Before",
"after": "After",
"clear": "Clear",
"apply": "Apply",
"matchAll": "Match All",
"matchAny": "Match Any",
"addRule": "Add Rule",
"removeRule": "Remove Rule",
"accept": "Yes",
"reject": "No"
&#125;
&#125;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123; Component, OnInit, OnDestroy &#125; from '@angular/core';
import &#123; PrimeNGConfig &#125; from 'primeng/api';
import &#123; TranslateService &#125; from '@ngx-translate/core';

@Component(&#123;
selector: 'app-root',
templateUrl: './app.component.html'
&#125;)
export class AppComponent implements OnInit, OnDestroy &#123;

constructor(private config: PrimeNGConfig, private translateService: TranslateService) &#123;&#125;

ngOnInit() &#123;
this.translateService.setDefaultLang('en');
&#125;

translate(lang: string) &#123;
this.translateService.use(lang);
this.translateService.get('primeng').subscribe(res => this.config.setTranslation(res));
&#125;
&#125;
</app-code>

<h5>Translation</h5>
<p>Translation API consists of various values used throughout the component library.</p>

<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>startsWith</td>
<td>Starts with</td>
</tr>
<tr>
<td>contains</td>
<td>Contains</td>
</tr>
<tr>
<td>notContains</td>
<td>Not contains</td>
</tr>
<tr>
<td>endsWith</td>
<td>Ends with</td>
</tr>
<tr>
<td>equals</td>
<td>Equals</td>
</tr>
<tr>
<td>notEquals</td>
<td>Not equals</td>
</tr>
<tr>
<td>lt</td>
<td>Less than</td>
</tr>
<tr>
<td>lte</td>
<td>Less than or equal to</td>
</tr>
<tr>
<td>gt</td>
<td>Greater than</td>
</tr>
<tr>
<td>gte</td>
<td>Great then or equals</td>
</tr>
<tr>
<td>is</td>
<td>Is</td>
</tr>
<tr>
<td>isNot</td>
<td>Is not</td>
</tr>
<tr>
<td>before</td>
<td>Before</td>
</tr>
<tr>
<td>after</td>
<td>After</td>
</tr>
<tr>
<td>clear</td>
<td>Clear</td>
</tr>
<tr>
<td>apply</td>
<td>Apply</td>
</tr>
<tr>
<td>matchAll</td>
<td>Match All</td>
</tr>
<tr>
<td>matchAny</td>
<td>Match Any</td>
</tr>
<tr>
<td>addRule</td>
<td>Add Rule</td>
</tr>
<tr>
<td>removeRule</td>
<td>Remove Rule</td>
</tr>
<tr>
<td>accept</td>
<td>Yes</td>
</tr>
<tr>
<td>reject</td>
<td>No</td>
</tr>
</tbody>
</table>
</div>

</div>
8 changes: 8 additions & 0 deletions src/app/showcase/components/i18n/i18n.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Component} from '@angular/core';

@Component({
templateUrl: './i18n.component.html'
})
export class I18NComponent {

}
17 changes: 17 additions & 0 deletions src/app/showcase/components/i18n/i18n.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {I18NComponent} from './i18n.component';
import {I18NRoutingModule} from './i18n-routing.module';
import {AppCodeModule} from '../../app.code.component';

@NgModule({
imports: [
CommonModule,
AppCodeModule,
I18NRoutingModule
],
declarations: [
I18NComponent
]
})
export class I18NModule {}
3 changes: 0 additions & 3 deletions src/app/showcase/components/setup/setup.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ <h5>Download</h5>
npm install primeicons --save
</app-code>

<h5>Load Configuration</h5>
<p>PrimeNG is distributed in commonjs format, a module manager of your choice is required and this guide provides samples for SystemJS, WebPack and Angular CLI.</p>

<h5>Import</h5>
<p>UI components are configured as modules, once PrimeNG is downloaded and configured, modules and apis can be imported from <i>primeng/&#123;module&#125;</i> shorthand in your application code. Documentation
of each component states the import path.</p>
Expand Down

0 comments on commit e14da72

Please sign in to comment.