Example #1
0
 /**
  * Confirms the directories required to build the mo and po files
  * exist.
  */
 private function ensureFolderStructure()
 {
     $localeDir = Strata::getLocalePath();
     if (!is_dir($localeDir)) {
         mkdir($localeDir);
     }
 }
Example #2
0
 /**
  * Assigns the theme's textdomain to Wordpress using 'load_theme_textdomain'.
  * @return boolean The result of load_theme_textdomain
  * @link https://codex.wordpress.org/Function_Reference/load_theme_textdomain
  */
 public function applyLocale()
 {
     $strataLocale = $this->getCurrentLocale();
     $app = Strata::app();
     if (!is_null($strataLocale)) {
         $message = setlocale(LC_ALL, $strataLocale->getCode() . '.UTF-8') ? "Localized to : " . $strataLocale->getCode() . ".UTF-8" : "Locale function is not available on this platform, or the given " . "local does not exist in this environment. Attempted to set: " . $strataLocale->getCode() . ".UTF-8";
         $app->setConfig("runtime.setlocale", $message);
     }
     // Set in PHP
     if (function_exists('bindtextdomain')) {
         $bound = bindtextdomain($this->getTextdomain(), Strata::getLocalePath());
         $app->setConfig("runtime.bindtextdomain", "PHP text domain was bound to <info>{$bound}</info>");
     }
     if (function_exists('textdomain')) {
         $bound = textdomain($this->getTextdomain());
         $app->setConfig("runtime.textdomain", "PHP message domain was bound to <info>{$bound}</info>");
     }
     // Set in WP
     global $locale;
     $locale = $strataLocale->getCode();
     return load_theme_textdomain($this->getTextdomain(), Strata::getLocalePath());
 }
Example #3
0
 /**
  * Returns the PO file path either by default or for
  * a specified environment
  * @param  string $env (optional) An environment
  * @return string
  */
 public function getMoFilePath($env = null)
 {
     $localeDir = Strata::getLocalePath();
     if (!is_null($env)) {
         return $localeDir . $this->getCode() . '-' . $env . '.mo';
     }
     return $localeDir . $this->getCode() . '.mo';
 }