Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created December 26, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hypeJunction/22c6fff20d0da61fa4ae738e5ba8f28e to your computer and use it in GitHub Desktop.
Save hypeJunction/22c6fff20d0da61fa4ae738e5ba8f28e to your computer and use it in GitHub Desktop.
Bulk replace language strings in Elgg
<?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