Created
December 26, 2016 14:55
-
-
Save hypeJunction/22c6fff20d0da61fa4ae738e5ba8f28e to your computer and use it in GitHub Desktop.
Bulk replace language strings in Elgg
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 | |
elgg_register_event_handler('upgrade', 'system', 'build_language_file', 999); | |
/** | |
* Rename: | |
* - Friends > Contacts | |
* | |
* @global array $GLOBALS | |
*/ | |
function build_language_file() { | |
global $GLOBALS; | |
$language = 'en'; | |
_elgg_services()->translator->reloadAllTranslations(); | |
$translations = $GLOBALS['_ELGG']->translations[$language]; | |
$map = [ | |
'friendships' => 'contacts', | |
'friendship' => 'contacts', | |
'friends' => 'contacts', | |
'friend' => 'contact', | |
]; | |
$output = []; | |
foreach ($map as $original_str => $target_str) { | |
foreach ($translations as $key => $translation) { | |
$original_translation = $translation; | |
$translation = str_replace(strtolower($original_str), strtolower($target_str), $translation); | |
$translation = str_replace(ucfirst($original_str), ucfirst($target_str), $translation); | |
if ($original_translation != $translation) { | |
$output[$key] = $translation; | |
$translations[$key] = $translation; | |
} | |
} | |
} | |
$file = fopen(__DIR__ . "/translations.php", 'w'); | |
$contents = var_export($output, true); | |
fwrite($file, "<?php\r\n\r\nreturn $contents;\r\n"); | |
fclose($file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment