daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Sep 23rd, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Loop through translation directory for given locale, find all PO files,
  4.  * and generate key/value pairs from ids and strings therein.
  5.  *
  6.  * @return array
  7.  * @params boolean $default
  8.  * @author Marissa Hogue
  9.  */
  10. function i18nPOStrings($default = false) {
  11.     static $messages = array();
  12.  
  13.     if ($default) {
  14.         $locale = get_instance()->config->item('language_ui_default')->url_name;
  15.     }
  16.     else {
  17.         $locale = get_instance()->config->item('language_ui')->url_name;
  18.     }
  19.  
  20.     if (!array_key_exists($locale, $messages) || $messages[$locale] === null) {
  21.         $strings = array();
  22.         $dir     = APPPATH . 'language/messages/*/';
  23.         $files    = glob($dir . '*.' . $locale . '.po');
  24.         $msgid    = null;
  25.         $msgstr   = '';
  26.        
  27.         foreach ($files as $file) {
  28.             $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  29.             foreach ($lines as $line) {
  30.                 if (preg_match("/^msgid/", $line)) {
  31.                     if ($msgid) {
  32.                         $strings[$msgid] = $msgstr;
  33.                         $msgstr = '';
  34.                     }  
  35.                     $msgid = preg_replace("/^msgid \"|\"$/", "", $line);
  36.                 }  
  37.                 elseif (preg_match("/^msgstr/", $line)) {
  38.                     $msgstr = preg_replace("/^msgstr \"|\"$/", "", $line);
  39.                 }  
  40.                 $strings[$msgid] = $msgstr;
  41.             }  
  42.         }  
  43.         $messages[$locale] = $strings;
  44.     }
  45.     return $messages[$locale];
  46. }
  47.  
  48. /**
  49.  * Get all UI Strings for current locale, replacing empty msgids with default value.
  50.  *
  51.  * @return array
  52.  * @author Marissa Hogue
  53.  */
  54. function getAllUIStrings() {
  55.     $messages = array();
  56.     $current = i18nPOStrings();
  57.     $default = i18nPOStrings(true);
  58.  
  59.     if ($current !== $default) {
  60.         $messages = array_merge($default, $current);
  61.     } else {
  62.         $messages = $default;
  63.     }
  64.     return $messages;
  65. }
  66.  
  67. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top