Hello everyone here is my question.
Im developing a site that will be translated to many languages.
Here is what i use:
- locale
- 18n
And I'm also using hook i18n_string_info() to refresh string translations and im getting some strange behaviour: ->
I will explain a little bit:
Every module that i've deloped have this hook that calls to a refresh_string_function that "scan php files looking for t() function and then it evals() it to send it to translation interface"
Why? Because if a user dont visit certaing pages strings wont appear at translation interface.
So it works fine for me but im getting unexpected behaviours:
All my t functions works have context and langcode. If i put langcode default to 'es' it won't work because it put the language default to English (site default) very weird.
Also, im getting Built-in interface as text group and as far is know when you create hook_18n_string_info() and hook_i18n_string_refresh() you create a new group.
Im doing this to get translators life eassier :S
Im new on drupal translations and maybe im doing things bad ... so at this point if you want to guide me how to do things right ill apreciate.
I've also add description for the files
$description = t('This is an example', array(), array('context' => 'i help translatiors with context example', 'langcode' => 'es'));
function myModule_i18n_string_info() {
$title = t('NAME', array(), array(MyModule::CONTEXT => 'NAME Module Name Title'));
$description = t('Vocabulary titles and term names for localizable vocabularies', array(), array(MyModule::CONTEXT => 'Module Name for translation description', MyModule::LANGCODE => MyModule::TRANSLATION_DEFAULT_LANGCODE));
$groups = array();
$groups[MyModule::MODULE_NAME][MyModule::TITLE] = $title;
$groups[MyModule::MODULE_NAME][MyModule::DESCRIPTION] = $description;
$groups[MyModule::MODULE_NAME][MyModule::FORMAT] = TRUE;
$groups[MyModule::MODULE_NAME][MyModule::TRANS_LIST] = TRUE;
$groups[MyModule::MODULE_NAME][MyModule::REFRESH_CALLBACK] = MyModule::REFRESH_FUNCTION;
return $groups;
}
function mymodule_i18n_string_refresh() {
mymodule_refresh_strings(MyModule::MODULE_NAME); //This function scan folder and files to search t() function calls and eval them
return TRUE; // Update completed with no issues
}
How is the best way to translate strings t() or maybe i18n functions. Thanks in advanced for reading and trying to help.
Regards everyone!
Comments
t() and i18n are for different purposes
The purpose or the t() function is to translate static strings / text, like:
The functions in i18n are built to allow you to translated and refresh dynamic strings that are stored in variables, something like:
If you want to force your t() strings to refresh, it would be much easier to write a simple script run by cron to grab the URL's from your site. Scanning the php for t() functions does not seem like a good idea at all.
Thank you for your answer :)
Thank you for your answer :)