Created
November 28, 2012 14:31
-
-
Save cam8001/4161656 to your computer and use it in GitHub Desktop.
Import translations po file on install.
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
/** | |
* 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