| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + import {Component} from 'angular2/angular2'; | ||
| 2 | + import {Control, ControlGroup} from 'angular2/forms'; | ||
| 3 | + | ||
| 4 | + import {IonicApp, App, Http} from 'ionic/ionic'; | ||
| 5 | + | ||
| 6 | + import {Translate} from 'ionic/ionic'; | ||
| 7 | + | ||
| 8 | + @App({ | ||
| 9 | + templateUrl: 'main.html' | ||
| 10 | + }) | ||
| 11 | + class MyApp { | ||
| 12 | + constructor(app: IonicApp, trans: Translate) { | ||
| 13 | + this.app = app; | ||
| 14 | + this.trans = trans; | ||
| 15 | + | ||
| 16 | + this.trans.translations('de', { | ||
| 17 | + 'Location': 'lage' | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + console.log(this.trans.translate('Location')); | ||
| 21 | + console.log(this.trans.translate('de', 'Location')); | ||
| 22 | + this.trans.setLanguage('de'); | ||
| 23 | + console.log(this.trans.translate('Location')); | ||
| 24 | + | ||
| 25 | + } | ||
| 26 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + <ion-menu #menu [content]="content"> | ||
| 2 | + <ion-toolbar><ion-title>Plugins</ion-title></ion-toolbar> | ||
| 3 | + <ion-content> | ||
| 4 | + <ion-list> | ||
| 5 | + <button ion-item *ng-for="#p of plugins" (click)="openPage(menu, p)"> | ||
| 6 | + {{p.title}} | ||
| 7 | + </button> | ||
| 8 | + </ion-list> | ||
| 9 | + </ion-content> | ||
| 10 | + </ion-menu> | ||
| 11 | + | ||
| 12 | + <ion-nav #content swipe-back-enabled="false" [root]="firstPage" id="myNav"></ion-nav> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ import {Popup} from '../popup/popup'; | |||
| 14 | 14 | import {FocusHolder} from '../form/focus-holder'; | |
| 15 | 15 | import {Events} from '../../util/events'; | |
| 16 | 16 | import {NavRegistry} from '../nav/nav-registry'; | |
| 17 | + import {Translate} from '../../translation/translate'; | ||
| 17 | 18 | ||
| 18 | 19 | /** | |
| 19 | 20 | * @name IonicApp | |
@@ -298,6 +299,8 @@ export function ionicBootstrap(rootComponentType, views, config) { | |||
| 298 | 299 | let modal = new Modal(app, config); | |
| 299 | 300 | let popup = new Popup(app, config); | |
| 300 | 301 | let events = new Events(); | |
| 302 | + let translate = new Translate(); | ||
| 303 | + console.log('Translate', translate); | ||
| 301 | 304 | let navRegistry = new NavRegistry(views); | |
| 302 | 305 | ||
| 303 | 306 | // add injectables that will be available to all child components | |
@@ -312,6 +315,7 @@ export function ionicBootstrap(rootComponentType, views, config) { | |||
| 312 | 315 | bind(Events).toValue(events), | |
| 313 | 316 | ROUTER_BINDINGS, | |
| 314 | 317 | bind(LocationStrategy).toClass(HashLocationStrategy), | |
| 318 | + bind(Translate).toValue(translate), | ||
| 315 | 319 | bind(NavRegistry).toValue(navRegistry) | |
| 316 | 320 | ]); | |
| 317 | 321 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,3 +24,5 @@ export * from './transitions/ios-transition' | |||
| 24 | 24 | export * from './transitions/md-transition' | |
| 25 | 25 | ||
| 26 | 26 | export * from './platform/plugins' | |
| 27 | + | ||
| 28 | + export * from './translation/translate' | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + import {Injectable} from 'angular2/angular2'; | ||
| 2 | + | ||
| 3 | + @Injectable() | ||
| 4 | + export class Translate { | ||
| 5 | + constructor() { | ||
| 6 | + this._transMap = {}; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + translations(lang, map) { | ||
| 10 | + this._transMap[lang] = map; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + setLanguage(lang) { | ||
| 14 | + this._language = lang; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + getTranslations(lang) { | ||
| 18 | + return this._transMap[lang]; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + translate(lang, key) { | ||
| 22 | + // If called with just one param, first is the key | ||
| 23 | + if(typeof key === 'undefined') { | ||
| 24 | + key = lang; | ||
| 25 | + lang = this._language; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + // If the language isn't specified, return the string passed. | ||
| 29 | + if(!lang) { | ||
| 30 | + return key; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + let map = this.getTranslations(lang); | ||
| 34 | + | ||
| 35 | + if(!map) { | ||
| 36 | + console.warn('I18N: No translation for key', key, 'using language', this._language); | ||
| 37 | + return ''; | ||
| 38 | + } | ||
| 39 | + return this._getTranslation(map, key); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + _getTranslation(map, key) { | ||
| 43 | + return map && map[key] || ''; | ||
| 44 | + } | ||
| 45 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments