5

I building a custom module for a multi-language Drupal 7 site where the default language is not english. Now I want to translate the module. Since my source strings are not in english I cannot use t().

The i18n module provides a i18n_string() function which would seem to do the job but I can't find my strings under admin/config/regional/translate/translate? I even implemented hook_i18n_string_info() to define my own textgroup, which shows up, but the strings don't!

What am I missing? Or is there a better way to translate strings that are in an other language than english?

  • 1
    Drupal assumes strings in your module are English. if they are not, you are bound to have problems :| – Mołot Nov 29 '13 at 13:42
  • 1
    The right way to do it would be to translate your source strings into English, pass them through the t() function and provide .pot files for the other languages you want to support. See stackoverflow.com/questions/5231496/… – Alfred Armstrong Nov 29 '13 at 16:11
  • This page on D.o shows how to translate strings that are not hard-coded and are not in english using the admin interface. If we can translate non hard-coded strings, isn't it possible to do the same with hard-coded strings? I really don't want to translate everything to english first. It is not a primary language for the site and seems like wasted effort. – daniels Dec 2 '13 at 19:12
2

We also have a lot of sites with a primary language which is not english.

After several different approaches we opted to write all user exposed string in our modules in english and translate them with the t() function.

We then use a crawler like wget to crawl the whole site (to get all strings into the translation database).

We enable the module Translation template extractor (https://www.drupal.org/project/potx) and export all strings from our module with this module in our languages.

The resulting language-files are edited and translations are added.

This file is then put in a "translations" subfolder in our module file with a *.po extension.

Uninstall and reinstall the module to activate the translations for your languages.

It may sound like a lot of work, because it is, but this is the only method that actually worked for us.

  • Well, in Drupal 8 we finally can build non-english sites but this seems to be the way to go for Drupal 7. – daniels Oct 17 '16 at 9:18
0

Go to admin/config/regional/i18n/strings and mark the default language as English, then everything would be working fine with you and you could also add different translation for different language other than English.

  • Maybe on another site I could, but this site has less content in english than in other languages... How would this make my strings to show up under admin/config/regional/translate/translate? In my code they look like this i18n_string('module:modulename', 'string not in english') – daniels Dec 2 '13 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.