本文整理汇总了PHP中Gettext\Translations::fromMoFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::fromMoFile方法的具体用法?PHP Translations::fromMoFile怎么用?PHP Translations::fromMoFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::fromMoFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_textdomain
/**
* Load a .mo file into the text domain.
*
* @since 6.1.13
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $path Path to the .mo file.
* @return bool True on success, false on failure.
*/
function load_textdomain($domain, $path)
{
global $t;
$app = \Liten\Liten::getInstance();
/**
* Filter text domain and/or .mo file path for loading translations.
*
* @since 6.1.13
*
* @param bool $override Should we override textdomain?. Default is false.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $path Path to the .mo file.
*/
$plugin_override = $app->hook->apply_filter('override_load_textdomain', false, $domain, $path);
if (true == $plugin_override) {
return true;
}
/**
* Fires before the .mo translation file is loaded.
*
* @since 6.1.13
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $path Path to the .mo file.
*/
$app->hook->do_action('load_textdomain', $domain, $path);
/**
* Filter .mo file path for loading translations for a specific text domain.
*
* @since 6.1.13
*
* @param string $path Path to the .mo file.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$mofile = $app->hook->apply_filter('load_textdomain_mofile', $path, $domain);
// Load only if the .mo file is present and readable.
if (!is_readable($mofile)) {
return false;
}
$translations = \Gettext\Translations::fromMoFile($mofile);
$t->loadTranslations($translations);
return true;
}
示例2: load
public static function load()
{
$locale = self::$locale;
# IMPORTANT: locale must be installed in server!
# sudo locale-gen es_ES.UTF-8
# sudo update-locale
// $_ENV["LANG"] = $locale;
// $_ENV["LANGUAGE"] = $locale;
// $_ENV["LC_MESSAGES"] = $locale;
// $_ENV["LC_PAPER"] = $locale;
// $_ENV["LC_TIME"] = $locale;
// $_ENV["LC_MONETARY"] = $locale;
// setlocale(LC_MESSAGES, $locale);
// setlocale(LC_COLLATE, $locale);
// setlocale(LC_TIME, $locale);
// setlocale(LC_MONETARY, $locale);
// bindtextdomain(self::$config['domain'], self::$config['storage']);
// bind_textdomain_codeset(self::$config['domain'], 'UTF-8');
// textdomain(self::$config['domain']);
# Also, we will work with gettext/gettext library
# because PHP gones crazy when mo files are updated
$path = base_path() . "/" . dirname(self::getFile(self::$locale));
$file = $path . '/' . self::$config['domain'];
if (is_file($file . '.mo')) {
$translations = Translations::fromMoFile($file . '.mo');
}
if (is_file($file . '.po')) {
$translationsPo = Translations::fromPoFile($file . '.po');
}
if ($translations) {
$translations->mergeWith($translationsPo);
} else {
$translations = $translationsPo;
}
if (!$translations) {
$translations = new Translations();
}
$translations->setLanguage($locale);
$translations->setHeader('LANGUAGE', $locale);
self::$currentTranslation = $translations;
// $trans = new Translator();
// $trans->loadTranslations($translations);
// Translator::initGettextFunctions($trans);
}
示例3: load
public static function load()
{
$locale = self::$locale . '.UTF-8';
# IMPORTANT: locale must be installed in server!
# sudo locale-gen es_ES.UTF-8
# sudo update-locale
putenv('LANG=' . $locale);
putenv('LANGUAGE=' . $locale);
putenv('LC_MESSAGES=' . $locale);
putenv('LC_PAPER=' . $locale);
putenv('LC_TIME=' . $locale);
putenv('LC_MONETARY=' . $locale);
setlocale(LC_MESSAGES, $locale);
setlocale(LC_COLLATE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_MONETARY, $locale);
bindtextdomain(self::$config['domain'], self::$config['storage']);
bind_textdomain_codeset(self::$config['domain'], 'UTF-8');
textdomain(self::$config['domain']);
# Also, we will work with gettext/gettext library
# because PHP gones crazy when mo files are updated
$path = dirname(self::getFile(self::$locale));
$file = $path . '/' . self::$config['domain'];
if (is_file($file . '.php')) {
$translations = $file . '.php';
} elseif (is_file($file . '.mo')) {
$translations = Translations::fromMoFile($file . '.mo');
} elseif (is_file($file . '.po')) {
$translations = Translations::fromPoFile($file . '.po');
} else {
$translations = new Translations();
}
Translator::initGettextFunctions((new Translator())->loadTranslations($translations));
}
示例4: execute
//.........这里部分代码省略.........
} elseif (empty($localeOption)) {
// List the currently package locales
foreach ($fh->getDirectoryContents($packageLanguagesDirectory) as $item) {
if (is_file("{$packageLanguagesDirectory}/{$item}/LC_MESSAGES/messages.mo") || is_file("{$baseDir}/{$item}/LC_MESSAGES/messages.po")) {
$locales[] = $item;
}
}
if (empty($locales)) {
// Let's use the core locales
$locales = Localization::getAvailableInterfaceLanguages();
}
} else {
// Normalize the locales (eg from it-it to it_IT)
foreach ($localeOption as $lo) {
$chunks = array();
foreach (explode('_', str_replace('-', '_', $lo)) as $index => $chunk) {
if ($index === 0) {
// Language (eg zh)
$chunks[] = strtolower($chunk);
} elseif (strlen($chunk) === 4) {
// Script (eg Hans)
$chunks[] = ucfirst(strtolower($chunk));
} else {
// Territory (eg CN)
$chunks[] = strtoupper($chunk);
}
}
$locales[] = implode('_', $chunks);
}
}
// Initialize the master translations file (.pot)
$pot = new Translations();
$pot->setHeader('Project-Id-Version', "{$packageHandle} {$packageVersion}");
$pot->setLanguage('en_US');
$pot->setHeader('Report-Msgid-Bugs-To', $input->getOption('contact'));
$pot->setHeader('Last-Translator', $input->getOption('translator'));
// Parse the package directory
$output->writeln('Parsing package contents');
foreach (\C5TL\Parser::getAllParsers() as $parser) {
if ($parser->canParseDirectory()) {
$output->write('- running parser "' . $parser->getParserName() . '"... ');
$parser->parseDirectory($packageDirectory, "packages/{$packageHandle}", $pot, false, $input->getOption('exclude-3rdparty'));
$output->writeln('done.');
}
}
// Save the pot file
$output->write('Saving .pot file... ');
if (!is_dir($packageLanguagesDirectory)) {
@mkdir($packageLanguagesDirectory, 0775, true);
if (!is_dir($packageLanguagesDirectory)) {
throw new Exception("Unable to create the directory {$packageLanguagesDirectory}");
}
}
$potFilename = "{$packageLanguagesDirectory}/messages.pot";
if ($pot->toPoFile($potFilename) === false) {
throw new Exception("Unable to save the .pot file to {$potFilename}");
}
$output->writeln('done.');
// Creating/updating the locale files
foreach ($locales as $locale) {
$output->writeln("Working on locale {$locale}");
$poDirectory = "{$packageLanguagesDirectory}/{$locale}/LC_MESSAGES";
$po = clone $pot;
$po->setLanguage($locale);
$poFile = "{$poDirectory}/messages.po";
$moFile = "{$poDirectory}/messages.mo";
if (is_file($poFile)) {
$output->write("- reading current .po file... ");
$oldPo = Translations::fromPoFile($poFile);
$output->writeln('done.');
} elseif (is_file($moFile)) {
$output->write("- decompiling current .mo file... ");
$oldPo = Translations::fromMoFile($poFile);
$output->writeln('done.');
} else {
$oldPo = null;
}
if ($oldPo !== null) {
$output->write("- merging translations... ");
$po->mergeWith($oldPo, 0);
$output->writeln('done.');
}
$output->write("- saving .po file... ");
if (!is_dir($poDirectory)) {
@mkdir($poDirectory, 0775, true);
if (!is_dir($poDirectory)) {
throw new Exception("Unable to create the directory {$poDirectory}");
}
}
$po->toPoFile($poFile);
$output->writeln('done.');
$output->write("- saving .mo file... ");
$po->toMoFile($moFile);
$output->writeln('done.');
}
} catch (Exception $x) {
$output->writeln($x->getMessage());
return 1;
}
}
示例5: addTranslation
/**
* @param string $path
*/
public static function addTranslation($path)
{
$file = new File($path);
if ($file->exists()) {
$parts = explode('.', $path);
$extension = $parts[count($parts) - 1];
switch ($extension) {
case 'po':
$translations = Translations::fromPoFile($path);
break;
case 'mo':
$translations = Translations::fromMoFile($path);
break;
case 'php':
$translations = Translations::fromPhpArrayFile($path);
break;
}
self::$activeTranslation->mergeWith($translations);
self::$t->loadTranslations(self::$activeTranslation);
}
}
示例6: loadFormatMo
private static function loadFormatMo($file)
{
return is_file($file . '.mo') ? Translations::fromMoFile($file . '.mo') : null;
}