Comments (8)
@plakak
angular-i18next 3.0.0-alpha just published
Added lazy namespace loading
You are welcome to test it =)
Complete version info and status: https://github.com/romanchuk/angular-i18next#roadmap-version-3
from angular-i18next.
@plakak Hello!
The thing is a feature to dynamicaly load namespaces for module/component is not implemented yet.
At current version you can provide ONE namespace as I18NEXT_NAMESPACE token to your module/component and pipe will automatically prefix your keys. For expample if your namespace is "common" and key is "key" it will call translation method with ["common:key", "key"] params. Of course init options must include this namespace.
I'm going to add this feature to roadmap.
from angular-i18next.
Thanks for the reply @Romanchuk. Great to see that coming.
The thing is that I have a common
namespace for things like: Submit
button, Go Back
button etc, while in a component I'd like to have translation specific to that component. So in my warranty-form.json
I don't have to include one more time translation for submit button since it's already in common.json
. That's for me is the main strength of i18next compared to similar libraries. Is there any way to achieve it right now? Something like a common namespace for all components while being able to namespace each component individually?
from angular-i18next.
@plakak Yes, you can do it. Actually i did it in the real app.
I had default namespace (translation.json) that had common localization dictionaries and child modules with their own namespaces.
i18next options:
ns: [
'translation', // this is default namespace with common keys
'validation',
'error',
'select2', // custom component namespace
'feature.warranty', // feature 1 namespace (WarrantyFeatureModule)
'feature.api01', // feature 2 namespace
'FileApi' // custom component namespace
]
In WarrantyFeatureModule module:
@NgModule({
providers: [
{
provide: I18NEXT_NAMESPACE,
useValue: 'feature.warranty'
}
....
export class WarrantyFeatureModule{
}
})
I18NEXT_NAMESPACE this will apply to i18next pipe in WarrantyFeatureModule child context and will treat key (example 'submit_title') as array of keys ['feature.warranty:submit_title', 'submit_title'] and i18next will search a key in
feature.warranty.json file (this feature specific dictionaries) and if there is no key 'submit_title' found, it will search in 'translation.json' file.
Also you can provide I18NEXT_NAMESPACE to your custom component and it will work the same way.
Remember i18next pipe will get the latest I18NEXT_NAMESPACE value provided in it's component tree.
i18next pipe checks only one specific namespace and one common/default namespace. So you can have only one common localization dictionary and many specific for module/component.
Finally to make it more scalable (Considering your initial question) i plan to:
- make I18NEXT_NAMESPACE to provide arrays of namespaces
- dynamically load these namespaces on bootstraping module/component
from angular-i18next.
@plakak Also, currently i'm working at demo app, that will include all possible features providing in current version. There would be example of using I18NEXT_NAMESPACE.
from angular-i18next.
Ah, OK - so the first ns
in the config array is taken as fallback/default. Cool, I can live with that until multiple namespaces are possible. Thanks, @Romanchuk 👍
from angular-i18next.
so the first ns in the config array is taken as fallback/default.
It's not quite right. i18next docs says:
Default ns setting up by 'defaultNS' option on i18next init. And it's default value is 'translation'.
Also there is 'fallbackNS' you might want to set up (i never used it)
from angular-i18next.
angular-i18next v3.0.0 relesed
from angular-i18next.
Related Issues (20)
- Is it possible to publish the 15.0 pre-release version to npm? HOT 2
- Interpolation is not working anymore HOT 4
- Property 'initialized' in type 'I18NextEvents' is not assignable to the same property in base type 'ITranslationEvents'. HOT 4
- Is it possible to use this library with Angular Universal and SSR? HOT 4
- New typings prevents passing interpolation to `ITranslationService` HOT 1
- Interpolation Format issues with numbers / dates or i18nextCap HOT 2
- Integration to Angular 16 HOT 9
- angular version issue HOT 1
- Check if there is a translation for the specified key HOT 1
- Update to last i18next version HOT 3
- Mock angular-i18next in Jest HOT 2
- Error when building project in docker HOT 3
- Nesting example HOT 1
- Consider providing a `ng add` schematics HOT 1
- Use Angular i18next in libs with nx workspace
- Unit test run error HOT 3
- Change Language without reloading page HOT 2
- Build error when updating to 14.2.0 with strict typing HOT 24
- Getting started with Angular v15 HOT 4
- Support i18next v22 HOT 2
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-i18next.