How to use Google to automatically translate UI strings

Lance Keay asked on September 15, 2017 15:09

Hi, Is there a way to get Kentico to automatically translate 3000+ Ui strings from English to another language? In looking at the docs, it would seem that we need to do this one string at a time.

Recent Answers


Trevor Fayas answered on September 15, 2017 16:44

If the 3000 UI strings are already Localization strings, you could use the Kentico API to handle this.

If it's Kentico's resource strings (resx), then you would probably need to programatically create the other resx files with the proper language abbreviation (CMS.es-ES.resx, CMS.de-DE.resx) etc. The system will use that pattern when determining which resource to pull.

Here's all the info you may need!

https://docs.kentico.com/k10/multilingual-websites/setting-up-a-multilingual-user-interface/working-with-resource-strings

  • Override resource strings in the Localization application.
  • Create a custom.resx file in the project's CMSResources folder and store your strings in this file. The file's content must have a valid XML structure for the .resx file format, including header information. You can copy the general structure from the default cms.resx file. To customize strings in non-English resource files, your custom file must use a name in format custom.[culture code].resx (for example, custom.fr-fr.resx for French).
0 votesVote for this answer Mark as a Correct answer

Lance Keay answered on September 15, 2017 16:55

They are in the DB. I know I can use the API, but I was wondering if I was missing some functionality or tool that would make this easier to do.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 15, 2017 16:58 (last edited on September 15, 2017 16:58)

Perhaps this will help?

https://docs.kentico.com/k10/multilingual-websites/configuring-translation-services/machine-translation-google-translate

Seems to be exactly what you are looking for. Forgot about this.

0 votesVote for this answer Mark as a Correct answer

Lance Keay answered on September 15, 2017 18:20

Nope. That just allows you to MANUALLY translate. String by string. Ugh.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 15, 2017 18:35 (last edited on September 15, 2017 18:36)

Well, then sadly Lance i think you're back to creating a script to do this.

If you can get an excel of the localization string code name and match it to the various languages, what i've done in the past is use excel to generate 'code' that then i can plug into a basic script to perform the task.

Here is the 1 liner of what you want to do programatically, if you can use the =CONCATENATE() method in excel, you can plug in your values into this one line and spit out the API code needed, just entering the Resource String Name, the Text, and the Culture Code:

    ResourceTranslationInfoProvider.SetResourceTranslationInfo(new ResourceTranslationInfo() {TranslationStringID = ResourceStringInfoProvider.GetResourceStringInfo("the.resourcename").StringID,TranslationText = "The Text",TranslationCultureID = CultureInfoProvider.GetCultureInfo("es-es").CultureID });

Create an excel with 4 columns: "Code" "Resource Name" "Text" and "Culture" (and add this to the first row) Then in the Code column, put the following in:

=CONCATENATE("ResourceTranslationInfoProvider.SetResourceTranslationInfo(new ResourceTranslationInfo() {TranslationStringID = ResourceStringInfoProvider.GetResourceStringInfo(""",B2,""").StringID,TranslationText = """,SUBSTITUTE(C2,"""","\"""),""",TranslationCultureID = CultureInfoProvider.GetCultureInfo(""",D2,""").CultureID });")

Add all your lines, drag the "Code" cell throughout the lines, and then you can just copy the Code column to get all your calls:

ResourceTranslationInfoProvider.SetResourceTranslationInfo(new ResourceTranslationInfo() {TranslationStringID = ResourceStringInfoProvider.GetResourceStringInfo("customhello").StringID,TranslationText = "Hello",TranslationCultureID = CultureInfoProvider.GetCultureInfo("en-us").CultureID });
ResourceTranslationInfoProvider.SetResourceTranslationInfo(new ResourceTranslationInfo() {TranslationStringID = ResourceStringInfoProvider.GetResourceStringInfo("custom.hello").StringID,TranslationText = "Bonjourno",TranslationCultureID = CultureInfoProvider.GetCultureInfo("fr-fr").CultureID });
ResourceTranslationInfoProvider.SetResourceTranslationInfo(new ResourceTranslationInfo() {TranslationStringID = ResourceStringInfoProvider.GetResourceStringInfo("custom.hello").StringID,TranslationText = "Hola",TranslationCultureID = CultureInfoProvider.GetCultureInfo("es-es").CultureID });

Paste that into a test page and run it! Best i can do for ya.

1 votesVote for this answer Mark as a Correct answer

Lance Keay answered on September 15, 2017 18:39

Thanks Trevor - but I'll just use the API. I was just wondering if I'd overlooked an easy-already built tool.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.