10.0.10 • Published 3 years ago

ondevio-translate-service v10.0.10

Weekly downloads
62
License
-
Repository
-
Last release
3 years ago

OndevioFeTranslate

This library was generated with Angular CLI version 10.2.0.

The library makes a translation of our application using the Google API Cloud Translation. For this it is necessary to have a valid key associated with the V2 API. Only two languages ​​can be used, source and target.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

How to use

Append dependencies in package.json file

"dependencies": {
    ...
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "ondevio-translate-service": "10.0.x",
    ...
  },

Import module library to app.module.ts, import library and append to NgModules imports list

import { OndevioTranslateModule } from 'ondevio-translate-service';

...
@NgModule({
    declarations: [        
       ...
    ],
    imports     : [
       ...
        OndevioTranslateModule,
    ],
    bootstrap   : [
        AppComponent
    ]
})

Import service to app.components.ts, import library, append to constructor function and set library configuration. It's possible to set local translations, reading i18n files and set in library config as dictionary or set null.

import { OndevioTranslateService } from 'ondevio-translate-service';
import { locale as es } from './i18n/es';
import { locale as en } from './i18n/en';
...
private dictionary: { [key: string]: any } = {
    'es': {
        lang: es.lang,
        data: es.data
    },
    'en': {
        lang: en.lang,
        data: en.data
    }
};
...
constructor(
     ...
    private _ondevioTranslate: OndevioTranslateService
    ) {
	...
	let serviceConfig = {
	    keyGoogleAPI: keyGoogleAPI,
	    urlGoogleAPI: urlGoogleAPI,
	    targetGoogleAPI: targetGoogleAPI,
	    sourceGoogleAPI: sourceGoogleAPI,
	    enableGooGleApiTranslate: production,
	    translateRequest: translateRequest,
        translateStorage: translateStorage,
        dictionary: dictionary,
        defaultLang: defaultLang
	};
	this._ondevioTranslate.setTranslateServiceConfig(serviceConfig);
	...
}

Params

  • keyGoogleAPI: Google API Key
  • urlGoogleAPI: Google API uri
  • targetGoogleAPI: target language
  • sourceGoogleAPI: source language
  • enableGooGleApiTranslate: Disable Google API call. Default: false
  • translateRequest: Name for google request array in localStorage
  • translateStorage: Name for translations array in localStorage
  • dictionary: Local app translations
  • defaultLang; Lang by default, if not exist 'es'

HTML translate

To get string translate from html, yo can use pipe or directive.

<span>{{ 'Hello World' | t }}</span>
<span odt>Hello World</span>

Export translations to i18n files

It's possible to export translations to i18n files. Append selector <ondevio-translate></ondevio-translate> in your component to download, edit or clear translations.

10.0.10

3 years ago

10.0.9

3 years ago

10.0.7

3 years ago

10.0.8

3 years ago

10.0.6

3 years ago

10.0.5

3 years ago

10.0.4

3 years ago

10.0.3

3 years ago

10.0.2

3 years ago

10.0.1

3 years ago

10.0.0

3 years ago