Code Monkey home page Code Monkey logo

Comments (4)

Rob--W avatar Rob--W commented on June 20, 2024

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.

cvan avatar cvan commented on June 20, 2024

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.

Rob--W avatar Rob--W commented on June 20, 2024

<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.

OleksandrSemenov avatar OleksandrSemenov commented on June 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.