Comments (4)
There is already a (sort-of) fallback mechanism in app-localize-behavior: it's called useKeyIfMissing
.
I think the biggest misconception in app-localize-behavior (and intl-messageformat) is, that you have to use abstract key values. You can use natural language instead (incl. special chars). e.g:
{
"fr": {
"Bonjour le monde!": "Bonjour le monde!"
},
"en": {
"l'œuf": "egg",
"Bonjour le monde!": "Hello world!"
}
}
So if you declare language="fr"
as your output-language, the egg would still be output as "l'œuf"
.
Limitations (...in my opinion good ones)
Complex formats won't be output, if the translation is missing. And why this is good, here some examples:
- Date "1/2/2018": for an Australian ("en-AU") this would be the "1st of February", for an American ("en") but the "2nd of January".
- Number "1.125": for an American ("en") this would be "1 and 1/8", for a German this would be "one-thousand-one-hundred-twenty-five".
Better approaches
- Output a
console.warn()
, if a translation is missing, so they can be found fast. - If you've got a language variant (e.g. Canadian French), but also ship to other languages (e.g. conventional French, German, ...) and don't want re-translate all fr-CA phrases that are the same in France, please see #120 (Feature Request: Fallback for language variants to it's superset).
from app-localize-behavior.
A fallback language is really an essential thing to have. I'm hoping this PR will get merged soon!
from app-localize-behavior.
@TrebuhD thank you for the review. I fixed the issues. You can take a look at my fork. I already merged it to master and added another feature for multi level structured translations.
from app-localize-behavior.
@toshovski Thanks! I've actually been using your fork in my project, and because of that I managed to find some more issues :) - check out my recent commits here.
from app-localize-behavior.
Related Issues (20)
- Reconsider format.js as core dependency HOT 2
- Support customizing the extracting of translations from resource file HOT 1
- How to use within a dom-repeat template
- Feature Request: Fallback for language variants to it's superset
- remove intl-messageformat polyfill HOT 2
- Missing string when no locale in the resources
- Typo in French translation
- Cannot set property 'IntlMessageFormat' of undefined HOT 8
- Error 'this.localize is not a function' on tests HOT 1
- Demo not working
- support to pass array value to localize() method
- upgrade demo to polymer 3 abandon polymer-legacy
- Resources request pending while localize already called
- Safari 9.1 El Capitan - Crash on localize HOT 1
- Feature request: let developer toggle showing the keys instead of translation
- Sub object in json sections HOT 3
- extending Polymer.AppLocalizeBehavior HOT 5
- Consider using `lang` property & attribute instead of `language`
- Feature Request: Add option to load resource (xhr) having withCredentials = true
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 app-localize-behavior.