Last active
October 4, 2015 23:48
-
-
Save DuaelFr/6e1c56809b832278591c to your computer and use it in GitHub Desktop.
Import local translations when enabling a module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_modules_enabled(). | |
* | |
* Install translations for all modules. | |
*/ | |
function myprofile_modules_enabled($modules) { | |
$langs = language_list(); | |
// For each enabled module. | |
foreach ($modules as $module) { | |
$translations_dir = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/translations'; | |
// For each enabled language. | |
foreach ($langs as $lang => $language) { | |
// Try to find the translations file that can be named | |
// - LANG.po | |
// - MODULE.LANG.po | |
$path = $translations_dir . '/' . $lang . '.po'; | |
if (!file_exists($path)) { | |
$path = $translations_dir . '/' . $module . '.' . $lang . '.po'; | |
} | |
// If the translation file exists. | |
if (file_exists($path)) { | |
// Load the file managed object from the database. | |
$file = reset(file_load_multiple(array(), array('uri' => $path))); | |
// If that file has never been managed, do it now. | |
if (empty($file)) { | |
$file = new stdClass(); | |
$file->fid = NULL; | |
$file->original = NULL; | |
$file->uri = $path; | |
file_save($file); | |
} | |
// Process import. | |
_locale_import_po($file, $lang, LOCALE_IMPORT_OVERWRITE, 'default'); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment