Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Loop through translation directory for given locale, find all PO files,
- * and generate key/value pairs from ids and strings therein.
- *
- * @return array
- * @params boolean $default
- * @author Marissa Hogue
- */
- function i18nPOStrings($default = false) {
- static $messages = array();
- if ($default) {
- $locale = get_instance()->config->item('language_ui_default')->url_name;
- }
- else {
- $locale = get_instance()->config->item('language_ui')->url_name;
- }
- if (!array_key_exists($locale, $messages) || $messages[$locale] === null) {
- $strings = array();
- $dir = APPPATH . 'language/messages/*/';
- $files = glob($dir . '*.' . $locale . '.po');
- $msgid = null;
- $msgstr = '';
- foreach ($files as $file) {
- $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($lines as $line) {
- if (preg_match("/^msgid/", $line)) {
- if ($msgid) {
- $strings[$msgid] = $msgstr;
- $msgstr = '';
- }
- $msgid = preg_replace("/^msgid \"|\"$/", "", $line);
- }
- elseif (preg_match("/^msgstr/", $line)) {
- $msgstr = preg_replace("/^msgstr \"|\"$/", "", $line);
- }
- $strings[$msgid] = $msgstr;
- }
- }
- $messages[$locale] = $strings;
- }
- return $messages[$locale];
- }
- /**
- * Get all UI Strings for current locale, replacing empty msgids with default value.
- *
- * @return array
- * @author Marissa Hogue
- */
- function getAllUIStrings() {
- $messages = array();
- $current = i18nPOStrings();
- $default = i18nPOStrings(true);
- if ($current !== $default) {
- $messages = array_merge($default, $current);
- } else {
- $messages = $default;
- }
- return $messages;
- }
- ?>
Add Comment
Please, Sign In to add comment