本文整理汇总了PHP中CBLib\Language\CBTxt::loadLanguageFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP CBTxt::loadLanguageFiles方法的具体用法?PHP CBTxt::loadLanguageFiles怎么用?PHP CBTxt::loadLanguageFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBLib\Language\CBTxt
的用法示例。
在下文中一共展示了CBTxt::loadLanguageFiles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Includes CB text file
*
* @param string $langPath Path of the language folder (without trailing '/')
* @param string $language ISO language (ISO 639-1 language code, a dash (-), then the ISO 3166-1 alpha-2 country code: e.g. 'en-GB') (which is also the name of the language folder)
* @param string $filename Filename of the php language file (ending with '.php')
* @param bool $fallback True (default): Falls back to default_language if $filename does not exist
* @return bool True if language loaded successfully
*/
public static function import($langPath, $language, $filename, $fallback = true)
{
if (isset(static::$self->importedLangPathFiles[$language][$langPath][$filename])) {
return true;
}
static::$self->loadLanguageFiles();
$file = $langPath . '/' . strtolower($language) . '/' . $filename;
if (!file_exists($file)) {
// If fallback is allowed, last resort is default_language without fallback:
return $fallback && static::import($langPath, 'default_language', $filename, false);
}
$extension = substr($file, -4, 4);
if ($extension == '.php') {
/** @noinspection PhpIncludeInspection */
$strings = (include_once $file);
} elseif ($extension == '.ini') {
$strings = parse_ini_file($file, false);
} else {
return false;
}
if (!is_array($strings)) {
return false;
}
/** @noinspection PhpDeprecationInspection */
static::addStrings($strings, $language);
// Now if we already import other non-default languages, we also want to import this file in those other languages:
if ($language != 'default_language' && count(static::$self->importedLangPathFiles) > 1) {
foreach (array_keys(static::$self->importedLangPathFiles) as $la) {
if ($la != 'default_language' && $la !== $language) {
static::importSameInLanguage($la);
}
}
}
static::$self->importedLangPathFiles[$language][$langPath][$filename] = true;
static::setCurrentLanguage($language);
return true;
}