loudenvier / kendo-global

Language packs for Telerik's Kendo UI (open source and commercial version)
87 stars 65 forks source link

Dutch translations #19

Closed marklagendijk closed 10 years ago

marklagendijk commented 11 years ago

@loudenvier, thanks for creating kendo-global, it helped me with creating a solution to localize the Kendo controls in my AngularJS app. Here are the Dutch (nl-NL) translations.

My app loads a JSON file with all the resources, and sets the labels for the KendoUI controls with it:

function initKendoLabels(){
    // Loop through all Components
    for(var componentName in Localize.labels.Controls){
        var component = Localize.labels.Controls[componentName];

        // Loop through all options within that component (eg: 'messages' or 'operators)
        for(var optionName in component){
            var optionLabels = component[optionName];

            // Extend the KendoUI labels for the current option
            if(kendo.ui[componentName] !== undefined){
                $.extend(kendo.ui[componentName].prototype.options[optionName], optionLabels);
            }
        }
    }
}

I think it might be a good idea to change the format of the localization files to something like this (1 object containing all the labels, + a simple function to set the labels from this object into Kendo).

I will open an issue about this idea where I will explain it further.

marklagendijk commented 11 years ago

As soon as this pull request is merged I will create a new pull request with a proposal to change the structure of the locale files. This new format is already commited to my kendo-global branch.

loudenvier commented 11 years ago

Your approach has its merits, but it requires the traversal of the data structure instead of simply overriding the default kendo objects. We can use your approach to make something that was already requested: on the fly language selection. I'll have to change your code a little bit, perhaps create a "KendoLocalizer" global object that has a method: ApplyLocale(languageCode) so anyone can all it at any time using: applyLocale('pt-BR') for example... But I can only merge it after migrating all other language files...

marklagendijk commented 11 years ago

Edit: I now see that the pullrequest also includes the new format. Apparently something went wrong there, I only wanted to do a pull for the Dutch translations, and after that do a pull request for the updated format.

I can convert all the other language files to the new format, too. I just wanted to know first whether you where open to the idea.

Dynamically loading the specified language file would be quite easy, the only caveat would be that people would need to initialize their Kendo UI controls after the language file would have been loaded:

$(document).ready(function(){
    KendoLocalizer.ApplyLocale('pt-BR', function(){
        // Init your Kendo UI controls here
    }

}

When I find some time (don't know when that will be, yet) I will convert all the other language files to the new format. After that we should find the best approach for dynamiccaly loading a locale file. With the labels already being in JSON format it would be quite easy to support both statically loading a language file (as it is now) and dynamiccaly loading:

  1. There would be two files for each language, one in my new format (Javascript file which sets the label) and one pure JSON.
  2. The dynamic aproach would work by loading the correct JSON file, and the static approach by just including the Javascript file.
loudenvier commented 11 years ago

I'm experimenting with this: we could create a "kendoLocalizer" object and each individual translation file, instead of applying itself automatically, could just add itselt to the list of available languages on the kendoLocalizer... which would have a single method: Localize(langCode), which would apply the same loop you've already created but to an entry for the language selected...