Tuesday, March 10, 2015

Add missing keys to resource files resx language

If you work on .net and some multi-language application, sooner or later you find the beauty of resx files. Put tke keys there and call them by the language user has chosen (or set by the browser). Cool, indeed. But as time flies, these language files become ... well, quite big, not huge. And if you have some 6 languages, the management of those files is something you are affraid of.

Why? While you code your application, youre not in the mood of entering a new key to each and every language file. So you just put them in the default language file (language.resx). And as you code and code, there are several keys you put in.

And then deployment. But you need to enter those keys into other languages. Send them to translators, copy the translations back?

OK, enough said. Borring, not worth a developer. :-) So, the solution...

1. The translation tool in the application (website): ResXManager
2. The "administrational" tool that adds all the missing keys from one file (languageNew.resx) to all the other files (language.de.resx, language.whatever.resx)
3. Small function to translate via google (but consider this to be quite unusable currently since if you send some heavy html, it will give you back all sorts of funny things), thxs to Piyush:


public string TranslateText(string input, string languagePair, Encoding encoding)
    {
        string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);

        string result = String.Empty;
        try
        {
            using (WebClient webClient = new WebClient())
            {
                webClient.Encoding = encoding;
                result = webClient.DownloadString(url);
            }

            Match m = Regex.Match(result, "(?<=overflow:auto">)(.*?)(?=)");

            if (m.Success)
                result = m.Value;
        }
        catch { }
        return result;
    }


The ResxManager and administration is avaliable here. Cant really explain more currently. Check the files and if you dont get it, comment here. Will be glad to explain.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.