Comments (4)
You don't have to duplicate the IDs in locales.ini
(which does not even have to be called locales.ini
, by the way. You can also use locale.properties
, foo.bar
, etc, as long as it is linked via <link rel="application/l18n">
).
This also works:
[*]
@import url(en.properties);
[nl]
@import url(nl.properties);
from webl10n.
Yep, I know that part. I mean more like I don't want to have to do this in locales.ini
[*]
tagline = Welcome to our homepage.
And this in index.html
:
<h1 data-l10n-id="tagline">Welcome to our homepage</h1>
I want to be able to just do something like
<h1>{{ _('Welcome to our homepage') }}</h1>
or
<h1 data-l10n>Welcome to our homepage</h1>
or
<h1 id="tagline">Welcome to our homepage</h1>
and have that automatically create an l10n identifier in the locales.ini
(and/or .properties
files, where applicable):
[*]
h1WelcomeToOurHomepage = Welcome to our homepage.
or
[*]
tagline = Welcome to our homepage.
from webl10n.
<h1>{{ _('Welcome to our homepage') }}</h1>
<h1 data-l10n>Welcome to our homepage</h1>
What if later you change this to "Welcome to our home page"
? Then you'd have to change the identifier in every other file.
<h1 id="tagline">Welcome to our homepage</h1>
Personally I would not do this, because it couples the identifiers of your HTML with the identifiers for i18n. E.g. if you want to use the same phrase twice, that's not possible when you use the HTML id attribute, because these must be unique within a document.
If you really want to use id attributes, you could do something like this (which I do not recommend for the previous reason):
document.webL10n.ready(function() {
var elements = document.querySelector('[id]');
for (var i = 0; i < elements.length; ++i) {
elements[i].setAttribute('data-l10n-id', elements[i].id);
}
document.webL10n.translate(document.body);
for (var i = 0; i < elements.length; ++i) {
elements[i].removeAttribute('data-l10n-id');
}
});
from webl10n.
please remember to remove semicolon in
@import url(en.properties);
Otherwise it will not be parsed
Right version is
@import url(en.properties)
from webl10n.
Related Issues (20)
- It doesn't recognize es-419 as a variant of [es]
- Hideous synchronous request HOT 1
- Unicode/encoding problem ? HOT 2
- Use of deprecated synchronous request HOT 4
- Callback parameter for setLanguage() HOT 2
- call variable HOT 8
- Add bower support HOT 1
- setLanguage() problem
- getL10nData not working in Chrome HOT 10
- Multi-line *.property file strings
- Fall back to primary subtag matching if an exact language code match fails
- Versions and releases
- Minify
- bower package HOT 2
- Use webL10n on documentFragment HOT 2
- Mixing plural and properties other than textContent HOT 9
- Plural rules are not updated when setLanguage() executed HOT 1
- Referencing other data-* attributes
- If browser gives ru (not ru-RU) the default language is used
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 webl10n.