mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
chore(translate): remove translate provider
Translate provider and TranslatePipe has been removed. Please use NG2-Translate instead: http://ionicframework.com/docs/v2/resources/ng2-translate/
This commit is contained in:
@ -20,7 +20,4 @@ export * from './animations/animation';
|
||||
export * from './transitions/page-transition';
|
||||
export * from './transitions/transition';
|
||||
|
||||
export * from './translation/translate';
|
||||
export * from './translation/translate_pipe';
|
||||
|
||||
export * from './navigation/nav-controller-base';
|
||||
|
@ -28,7 +28,6 @@ import { PopoverController } from './components/popover/popover';
|
||||
import { QueryParams, setupQueryParams, UrlToken } from './platform/query-params';
|
||||
import { TapClick, setupTapClick } from './components/tap-click/tap-click';
|
||||
import { ToastController } from './components/toast/toast';
|
||||
import { Translate } from './translation/translate';
|
||||
import { registerModeConfigs } from './config/mode-registry';
|
||||
import { registerTransitions } from './transitions/transition-registry';
|
||||
import { TransitionController } from './transitions/transition-controller';
|
||||
@ -180,7 +179,6 @@ export class IonicModule {
|
||||
PopoverController,
|
||||
TapClick,
|
||||
ToastController,
|
||||
Translate,
|
||||
TransitionController,
|
||||
|
||||
{ provide: LocationStrategy, useFactory: provideLocationStrategy, deps: [ PlatformLocation, [ new Inject(APP_BASE_HREF), new Optional()], Config ] },
|
||||
|
@ -1,67 +0,0 @@
|
||||
/**
|
||||
* @private
|
||||
* Provide multi-language and i18n support in your app. Translate works by
|
||||
* mapping full strings to language translated ones. That means that you don't
|
||||
* need to provide strings for your default language, just new languages.
|
||||
*
|
||||
* Note: The Angular team will be building an
|
||||
* [Localization/Internationalization](https://docs.google.com/document/d/1mwyOFsAD-bPoXTk3Hthq0CAcGXCUw-BtTJMR4nGTY-0/view#heading=h.ixg45w3363q)
|
||||
* provider, so this Translation provider may not be further developed.
|
||||
*
|
||||
* @usage
|
||||
* ```js
|
||||
* Translate.translations({
|
||||
* 'de': {
|
||||
* 'Welcome to MyApp': 'Willkommen auf'
|
||||
* }
|
||||
* })
|
||||
*
|
||||
* Changing the default language:
|
||||
*
|
||||
* Translate.setLanguage('de');
|
||||
* ```
|
||||
*
|
||||
* Usage in a template:
|
||||
*
|
||||
* ```js
|
||||
* <span>{{ 'Welcome to MyApp' | translate }}
|
||||
* ```
|
||||
*/
|
||||
export class Translate {
|
||||
private _transMap: any = {};
|
||||
private _language: any = {};
|
||||
|
||||
translations(lang: any, map: any) {
|
||||
this._transMap[lang] = map;
|
||||
}
|
||||
|
||||
setLanguage(lang: any) {
|
||||
this._language = lang;
|
||||
console.warn('Translate provider and TranslatePipe has been deprecated and will be removed in the next version. Please use NG2-Translate instead: http://ionicframework.com/docs/v2/resources/ng2-translate/');
|
||||
}
|
||||
|
||||
getTranslations(lang: any) {
|
||||
return this._transMap[lang];
|
||||
}
|
||||
|
||||
translate(key: any, lang: any) {
|
||||
// If the language isn't specified and we have no overridden one, return the string passed.
|
||||
if (!lang && !this._language) {
|
||||
return key;
|
||||
}
|
||||
|
||||
let setLanguage = lang || this._language;
|
||||
|
||||
let map = this.getTranslations(setLanguage);
|
||||
|
||||
if (!map) {
|
||||
console.warn('I18N: No translation for key', key, 'using language', setLanguage);
|
||||
return '';
|
||||
}
|
||||
return this._getTranslation(map, key);
|
||||
}
|
||||
|
||||
_getTranslation(map: any, key: any) {
|
||||
return map && map[key] || '';
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
import { Injectable, Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
import { Translate } from './translate';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* The Translate pipe makes it easy to translate strings.
|
||||
*
|
||||
* @usage
|
||||
* Translate using the current language or language set through Translate.setLanguage
|
||||
* {{ 'Please enter your location' | translate }}
|
||||
*
|
||||
* Translate using a specific language
|
||||
* {{ 'Please enter your location' | translate:"de" }}
|
||||
*/
|
||||
@Pipe({name: 'translate'})
|
||||
@Injectable()
|
||||
export class TranslatePipe implements PipeTransform {
|
||||
private translate: any = {};
|
||||
|
||||
constructor(translate: Translate) {
|
||||
this.translate = translate;
|
||||
}
|
||||
transform(value: any, args: any) {
|
||||
let lang: any;
|
||||
if (args.length > 0) {
|
||||
lang = args[0];
|
||||
}
|
||||
return this.translate.translate(value, lang);
|
||||
}
|
||||
|
||||
supports(obj: any) { return true; }
|
||||
}
|
Reference in New Issue
Block a user