Created
April 12, 2011 12:21
-
-
Save simme/915409 to your computer and use it in GitHub Desktop.
Update translations on a Drupal site
This file contains 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 | |
// Update translations | |
// This might need some 'splainin': | |
// RecursiveDirectoryIterator together with RecursiveIteratorIterator | |
// loops through all files in the give root directory. | |
// RegexIterator filters out the files we want (modules-topbar and | |
// themes-xskane) translations in this case. Matches the languages code | |
// and filename. Then we loop through it and win. | |
$di = new RecursiveDirectoryIterator('./sites/all/translations/'); | |
$it = new RecursiveIteratorIterator($di); | |
$po = new RegexIterator( | |
$it, | |
'/^(?:.*\/)?(?:modules-topbar|themes-xskane)\.([a-z]{2,})\.po$/', // Tweak to match your modules/themes | |
RecursiveRegexIterator::GET_MATCH | |
); | |
require('includes/locale.inc'); | |
$languages = language_list(); | |
foreach ($po as $translation) { | |
$file = (object) array('filepath' => $translation[0]); | |
$langcode = $translation[1]; | |
// Only import for activated languages | |
if (array_key_exists($langcode, $languages)) { | |
if (!_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE)) { | |
drupal_set_message('Failed to import ' . $file->filepath); | |
} | |
} | |
} |
I have not. :P I just made the old skane.com a bit prettier.
And I got to use RegexIterator which it turns out, is awesome! :D
Seems like some crazy stuff there! I imagine a certain import of a norwegian API could have made good use of that :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've seen http://drupal.org/project/l10n_update as well?