-
-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow default translation without using MissingTranslationHandler #160
Comments
I use this pattern a lot in the Angular 1 project I'm porting to Angular 2. It's really useful for gracefully defaulting values. For example if you want to support specific translations, but fallback to a general string // field = 'name', collection = 'animals'
let generalFieldTitle = new TranslatePipe()
.transform(`fields.${field}`);
//=> 'Name'
let specificFieldTitle = new TranslatePipe()
.transform(`${collection}.fields.${field}`, {default: generalFieldTitle});
//=> 'Animal Name', but it would be 'Name' if collection was 'foobars' with translations like en = {
fields: {
name: 'Name'
},
animals: {
// This may or may not exist
name: 'Animal Name'
}
} |
Wouldn't |
That would be good! However if the translation key is not yet present in the default translation file that outputs as example.translation.key |
Often you have an error response from the server. Typical Error{Code:111,Message:'yikes'}
|
When a translation is missing it would be ideal if we could pass in a default fallback string to use if no translation is found (in current or default language).
Suggested syntax:
A specific use case for this is a dropdown list where the first few items (such as item value=0 , text= [Unknown] are translated), but the other items are driven by an external data source and may or may not have a translation.
The text was updated successfully, but these errors were encountered: