Skip to content

Instantly share code, notes, and snippets.

@cam8001
Created November 28, 2012 14:31
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 cam8001/4161656 to your computer and use it in GitHub Desktop.
Save cam8001/4161656 to your computer and use it in GitHub Desktop.
Import translations po file on install.
/**
* Imports translations from a .po file into the local database.
*
* @param string $filepath
* Full filepath to a .po translations file.
*/
function maya_updates_api_import_translations($filepath, $langcode) {
_maya_updates_api_load_locale();
drupal_load('module', 'file');
watchdog(__FUNCTION__, 'Importing @file string translations.', array('@file' => $filepath), WATCHDOG_NOTICE);
// No need to use drupal_basename() in this case, and it requires loading up file.inc.
$file = file_save_data(file_get_contents($filepath), 'public://' . basename($filepath), FILE_EXISTS_RENAME);
_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, 'default');
}
/**
* Loads locale module files which are required to import new languages and
* translations.
*
* @see maya_updates_api_enable_default_language()
* @see maya_updates_api_import_translations()
*/
function _maya_updates_api_load_locale() {
drupal_load('module', 'locale');
module_load_include('inc', 'locale');
module_load_include('inc', 'locale', 'locale.admin');
require_once DRUPAL_ROOT . '/includes/locale.inc';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment