Comments (3)
Hello. Usually the translation is used in templates. Service
does not exist in object-orienting languages: there are classes and also the components are classes.
However, this library has the LocalizationService
class, which provides the translation service. After it has been initialized in the main component, you can take advantage of the dependency injection in all children components or classes that recall it.
It has a translate
method of Observable type, you can invoke it by RX to get the translation of the desired key, something like this:
constructor(public localization: LocalizationService) {
var translatedTitle: string;
this.localization.translate("TITLE").forEach(
// Next.
(value: string) => {
translatedTitle = value;
}, null
).then(() => console.log(translatedTitle));
}
from angular-l10n.
Great!
2016-04-27 17:13 GMT-03:00 Roberto Simonetti [email protected]:
Hello. Usually the translation is used in templates. Service does not
exist in object-orienting languages: there are classes and also the
components are classes.
However, this library has the LocalizationService class, which provides
the translation service. After it has been initialized in the main
component, you can take advantage of the dependency injection in all
children components or classes that recall it.
It has a translate method of Observable type, you can invoke it by RX to
get the translation of the desired key, something like this:constructor(public localization: LocalizationService) { var translatedTitle: string; this.localization.translate("TITLE").forEach( // Next. (value: string) => { translatedTitle = value; }, null ).then(() => console.log(translatedTitle)); }
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#3 (comment)
from angular-l10n.
I update and close this answer: Now you have two methods of LocalizationService
to call in the component:
translate
of string type;translateAsync
of Observable type.
Greetings.
from angular-l10n.
Related Issues (20)
- locale.language always empty string after upgrade from Angular 9 -> 10 HOT 6
- Unit tests question HOT 9
- Module parse failed: Identifier 'ɵngcc0' has already been declared build error HOT 2
- angular-l10n (formatLanguage): Invalid language thrown HOT 4
- Function calls are not supported in decorators but 'L10nTranslationModule' was called HOT 2
- How i can translate the word HOT 1
- feature: easily register and bundle translation data with a lazy loaded module HOT 3
- Number format options HOT 7
- Release a version with peerDependencies compatible with RxJS v7 HOT 3
- split big files HOT 2
- Namespace 'Intl' has no exported member 'RelativeTimeFormatOptions' HOT 3
- [Question] Differences / Benefits vs ngx-translate? HOT 3
- Setting available languages from Database HOT 5
- Problems after Upgrading HOT 2
- locale.language is empty, Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found HOT 2
- Incorrect date format HOT 2
- Namespace 'Intl' has no exported member 'ListFormatOptions' HOT 1
- possibility to configure PARSE_DATE_STYLE const. Configure full, long,medium,short options HOT 2
- Refreshing page redirects to fallback HOT 5
- Opening subpages in tabs works - sometimes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-l10n.