alamid icon indicating copy to clipboard operation
alamid copied to clipboard

Internationalization and Localization

Open sbat opened this issue 12 years ago • 19 comments

Please optimize your framework for international requirements.

sbat avatar Mar 06 '12 15:03 sbat

i'll try to find some suitable modules and discuss them with @jhnns

meaku avatar Mar 06 '12 15:03 meaku

I like the idea that the translation is also some kind of a model, which is binded to the view.

topa avatar Mar 12 '12 09:03 topa

I did some research... We had a simple approach for the BBC but i'm not sure if it is really fitting our requirements.

BBC-way

  • include a node-module for each language and file with subfolders for each language
  • include this file in the view depending on the language used i.e. require("en/myView.js")

Problems

  • as views are classes they are being compiled, and we can't decide which language to deliver on the server while rendering
  • we will need a special require for the language file to load the suitable file/module on the client for each user
  • there are missing features like pluralization and data-formatting

Other Modules

meaku avatar May 29 '12 12:05 meaku

Found on tumblr


var __ = (function() {

        var translation = {
            "by": "von ",
            "(default)": "(Standardeinstellung)",
            "This page overrides a built-in URL.": "Diese Seite überschreibt eine eingebaute URL.",
            "Edit HTML": "HTML bearbeiten",
            "Custom theme": "Benutzerdefiniertes Template",
            "Use": "Anwenden",
            "Saving...": "senden...",
            "You have unsaved changes.": "Du hast ungespeicherte Änderungen",
            "Updating...": "Update läuft...",
            "Update preview": "Vorschau aktualisieren"
        };

        return function(string) {
            return translation[string] || string;
        };

    })();

meaku avatar Jun 01 '12 15:06 meaku

@meaku could be interessting for you:

https://webtranslateit.com/en/projects/3020-Diaspora WebTranslateIt is a translation tool to help translate documents and software from a web browser.

sbat avatar Jun 04 '12 05:06 sbat

Thanks @sbat! This really looks nice!

I checked which file-formats they are supporting and it looks good :) File Formats

JSON hash - As used by i18next and i18n-node libraries

So we should focus on i18next as it seems mature and would work with the webtranslateit

meaku avatar Jun 04 '12 08:06 meaku

But the services is not for free: https://webtranslateit.com/en/plans

Maybe there is a free service...

meaku avatar Jun 04 '12 08:06 meaku

500 segments are for free. But yes @meaku maybe there is a free service!

sbat avatar Jun 05 '12 06:06 sbat

This one looks interesting: https://www.transifex.net/plans/

meaku avatar Jun 10 '12 20:06 meaku

Should i18 be part of alamid or is it up to the application developers? @sbat @jhnns @topa

meaku avatar Jul 27 '12 07:07 meaku

I see i18n as some kind of rendering. Our Views are able to render data from Models. I think we should find a way to use these mechanism also for i18n, because it already exists and works just nice. Maybe we introduce a special data-label='de_beer'. (=) Before a Page or View is displayed it's nodes will be scanned for this attribute and some kind of a fancy Translator will return a Model that contains the translations for the current language.

MightyPageChanger.changePage("anyPage");

//In the changePage()
needTranslation = jQuery(anyPage.getNode()).find("[data-label]")

translation = TranslationService.get(needTranslation)

Then there will be a Schema created out of the translation which will be set for a Model. This Model will be bound to the Page.

alamid should provide this mechanism and the app-devs must implement the service.

topa avatar Jul 27 '12 09:07 topa

Internationalization is very tricky because there are problems that we might don't know about yet. For instance, some languages have multiple plural forms. E.g. the plural is different if you have 2 beers or 3 beers. Therefore alamid should not have a specific framework baked-in because there is no framework that fits for every use-case. But alamid should offer a good way to costumize its behaviour.

I think there are already good ways to implement i18n. For instance: you could use the constructor of a DisplayObject. There you can walk over the node and inject all translations. Therefore it would be reasonable to extend the DisplayObject so you don't have to take care of that for every DisplayObject you implement.

jhnns avatar Jul 30 '12 08:07 jhnns

The problem @jhnns has mentioned can be solved by a good naming for the labels. But you'll have a lot of quite redundant translations.

topa avatar Jul 30 '12 08:07 topa

So it should be up to the developers to take care of i18n in the first place. I'll leave this issue open because we should check out how it works for us with our alamid-based projects.

meaku avatar Aug 01 '12 09:08 meaku

Since you are using webpack: https://github.com/webpack/i18n-loader

sokra avatar Sep 01 '12 15:09 sokra

@sokra: you i18n-loader looks nice! We might implement it.

There are still some problems with i18n that still have to be solved, like language specific date-formatting and the like.

meaku avatar Sep 03 '12 08:09 meaku

The i18n-loader just provides some basic stuff for internationalization and you can extend it to your demands.

date-formatting may be solved like this:

// format.js
exports.date = function(d) {
  return d.getFullYear() + "/" + d.getMonth() + "/" + d.getDate();
}
// de.format.js
exports.date = function(d) {
  return d.getDate() + "." + d.getMonth() + "." + d.getFullYear();
}
var dateFormat = require("i18n/choose!./nls/format").date;

sokra avatar Sep 03 '12 09:09 sokra

It's definitely worth a try. Maybe we can use the i18n loader in conjunction with another i18n framework.

jhnns avatar Sep 05 '12 14:09 jhnns

:) It should be flexible, but the internals are not very well documented. Do not hesitate to ask me.

sokra avatar Sep 05 '12 14:09 sokra