本文整理汇总了PHP中i18n::default_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::default_locale方法的具体用法?PHP i18n::default_locale怎么用?PHP i18n::default_locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类i18n
的用法示例。
在下文中一共展示了i18n::default_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
function setUp() {
parent::setUp();
$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
FileSystem::makeFolder($this->alternateBaseSavePath);
Director::setBaseFolder($this->alternateBasePath);
// Push a template loader running from the fake webroot onto the stack.
$templateManifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
$templateManifest->regenerate(false);
SS_TemplateLoader::instance()->pushManifest($templateManifest);
$this->_oldTheme = SSViewer::current_theme();
SSViewer::set_theme('testtheme1');
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
SS_ClassLoader::instance()->pushManifest($classManifest);
$this->originalLocale = i18n::get_locale();
// Override default adapter to avoid cached translations between tests.
// Emulates behaviour in i18n::get_translators()
$this->origAdapter = i18n::get_translator('core');
$adapter = new Zend_Translate(array(
'adapter' => 'i18nSSLegacyAdapter',
'locale' => i18n::default_locale(),
'disableNotices' => true,
));
i18n::register_translator($adapter, 'core');
$adapter->removeCache();
i18n::include_by_locale('en');
}
示例2: __construct
/**
* @param $locale
*/
public function __construct($locale = null)
{
$this->defaultLocale = $locale ? $locale : i18n::get_lang_from_locale(i18n::default_locale());
$this->basePath = Director::baseFolder();
$this->baseSavePath = Director::baseFolder();
parent::__construct();
}
示例3: __construct
/**
* @param $locale
*/
function __construct($locale = null) {
$this->defaultLocale = ($locale) ? $locale : i18n::default_locale();
$this->basePath = Director::baseFolder();
$this->baseSavePath = Director::baseFolder();
parent::__construct();
}
示例4: getLocaleFromURL
/**
* getLocaleFromURL
* finds the locale of the url passed into the function, and returns the associated locale
*
* @param string $host URL used to retrieve tld from.
* @return locale associated with tld: (.de == de_DE)
*
*/
public function getLocaleFromURL($host)
{
$locale = i18n::default_locale();
//be able to return default locale if nothing is found.
if ($tld = self::getTLD($host)) {
$locale = self::$domain_locale_map[$tld];
}
return $locale;
}
示例5: __construct
public function __construct()
{
parent::__construct();
//Setting the locale has to happen in the constructor (using the setUp and tearDown methods doesn't work)
//This is because the test relies on the yaml file being interpreted according to a particular date format
//and this setup occurs before the setUp method is run
$this->local = i18n::default_locale();
i18n::set_default_locale('en_US');
}
示例6: setUp
public function setUp()
{
parent::setUp();
$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
Filesystem::makeFolder($this->alternateBaseSavePath);
Config::inst()->update('Director', 'alternate_base_folder', $this->alternateBasePath);
// Replace old template loader with new one with alternate base path
$this->_oldLoader = ThemeResourceLoader::instance();
ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
$this->_oldTheme = Config::inst()->get('SSViewer', 'theme');
Config::inst()->update('SSViewer', 'theme', 'testtheme1');
$classManifest = new SS_ClassManifest($this->alternateBasePath, false, true, false);
SS_ClassLoader::instance()->pushManifest($classManifest);
$this->originalLocale = i18n::get_locale();
// Override default adapter to avoid cached translations between tests.
// Emulates behaviour in i18n::get_translators()
$this->origAdapter = i18n::get_translator('core');
$adapter = new Zend_Translate(array('adapter' => 'i18nSSLegacyAdapter', 'locale' => i18n::default_locale(), 'disableNotices' => true));
i18n::register_translator($adapter, 'core');
$adapter->removeCache();
i18n::include_by_locale('en');
}
示例7: testCollectFromFilesystemAndWriteMasterTables
function testCollectFromFilesystemAndWriteMasterTables()
{
$defaultlocal = i18n::default_locale();
$local = i18n::get_locale();
i18n::set_locale('en_US');
//set the locale to the US locale expected in the asserts
i18n::set_default_locale('en_US');
$c = new i18nTextCollector();
$c->basePath = $this->alternateBasePath;
$c->baseSavePath = $this->alternateBaseSavePath;
$c->run();
// i18ntestmodule
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
$this->assertTrue(file_exists($moduleLangFile), 'Master language file can be written to modules /lang folder');
$moduleLangFileContent = file_get_contents($moduleLangFile);
$this->assertContains("\$lang['en_US']['i18nTestModule']['ADDITION'] = 'Addition';", $moduleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestModule']['ENTITY'] = array(\n\t'Entity with \"Double Quotes\"',\n\tPR_LOW,\n\t'Comment for entity'\n);", $moduleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestModule']['MAINTEMPLATE'] = 'Main Template';", $moduleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestModule']['OTHERENTITY'] = 'Other Entity';", $moduleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';", $moduleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';", $moduleLangFileContent);
// i18nothermodule
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php';
$this->assertTrue(file_exists($otherModuleLangFile), 'Master language file can be written to modules /lang folder');
$otherModuleLangFileContent = file_get_contents($otherModuleLangFile);
$this->assertContains("\$lang['en_US']['i18nOtherModule']['ENTITY'] = 'Other Module Entity';", $otherModuleLangFileContent);
$this->assertContains("\$lang['en_US']['i18nOtherModule']['MAINTEMPLATE'] = 'Main Template Other Module';", $otherModuleLangFileContent);
// testtheme1
$theme1LangFile = "{$this->alternateBaseSavePath}/themes/testtheme1/lang/" . $c->getDefaultLocale() . '.php';
$this->assertTrue(file_exists($theme1LangFile), 'Master theme language file can be written to themes/testtheme1 /lang folder');
$theme1LangFileContent = file_get_contents($theme1LangFile);
$this->assertContains("\$lang['en_US']['i18nTestTheme1']['MAINTEMPLATE'] = 'Theme1 Main Template';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1']['LAYOUTTEMPLATE'] = 'Theme1 Layout Template';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1']['SPRINTFNAMESPACE'] = 'Theme1 My replacement: %s';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1.ss']['LAYOUTTEMPLATENONAMESPACE'] = 'Theme1 Layout Template no namespace';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1.ss']['SPRINTFNONAMESPACE'] = 'Theme1 My replacement no namespace: %s';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1Include']['SPRINTFINCLUDENAMESPACE'] = 'Theme1 My include replacement: %s';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1Include']['WITHNAMESPACE'] = 'Theme1 Include Entity with Namespace';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1Include.ss']['NONAMESPACE'] = 'Theme1 Include Entity without Namespace';", $theme1LangFileContent);
$this->assertContains("\$lang['en_US']['i18nTestTheme1Include.ss']['SPRINTFINCLUDENONAMESPACE'] = 'Theme1 My include replacement no namespace: %s';", $theme1LangFileContent);
// testtheme2
$theme2LangFile = "{$this->alternateBaseSavePath}/themes/testtheme2/lang/" . $c->getDefaultLocale() . '.php';
$this->assertTrue(file_exists($theme2LangFile), 'Master theme language file can be written to themes/testtheme2 /lang folder');
$theme2LangFileContent = file_get_contents($theme2LangFile);
$this->assertContains("\$lang['en_US']['i18nTestTheme2']['MAINTEMPLATE'] = 'Theme2 Main Template';", $theme2LangFileContent);
i18n::set_locale($local);
//set the locale to the US locale expected in the asserts
+i18n::set_default_locale($defaultlocal);
}
示例8: add_i18n_javascript
/**
* Add i18n files from the given javascript directory. SilverStripe expects that the given
* directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js,
* etc.
*
* @param string $langDir The JavaScript lang directory, relative to the site root, e.g.,
* 'framework/javascript/lang'
* @param bool $return Return all relative file paths rather than including them in
* requirements
* @param bool $langOnly Only include language files, not the base libraries
*
* @return array
*/
public function add_i18n_javascript($langDir, $return = false, $langOnly = false)
{
$files = array();
$base = Director::baseFolder() . '/';
if (i18n::config()->js_i18n) {
// Include i18n.js even if no languages are found. The fact that
// add_i18n_javascript() was called indicates that the methods in
// here are needed.
if (!$langOnly) {
$files[] = FRAMEWORK_DIR . '/javascript/i18n.js';
}
if (substr($langDir, -1) != '/') {
$langDir .= '/';
}
$candidates = array('en.js', 'en_US.js', i18n::get_lang_from_locale(i18n::default_locale()) . '.js', i18n::default_locale() . '.js', i18n::get_lang_from_locale(i18n::get_locale()) . '.js', i18n::get_locale() . '.js');
foreach ($candidates as $candidate) {
if (file_exists($base . DIRECTORY_SEPARATOR . $langDir . $candidate)) {
$files[] = $langDir . $candidate;
}
}
} else {
// Stub i18n implementation for when i18n is disabled.
if (!$langOnly) {
$files[] = FRAMEWORK_DIR . '/javascript/i18nx.js';
}
}
if ($return) {
return $files;
} else {
foreach ($files as $file) {
$this->javascript($file);
}
}
}
示例9: setUp
function setUp()
{
// Mark test as being run
$this->originalIsRunningTest = self::$is_running_test;
self::$is_running_test = true;
// i18n needs to be set to the defaults or tests fail
i18n::set_locale(i18n::default_locale());
i18n::set_date_format(null);
i18n::set_time_format(null);
// Remove password validation
$this->originalMemberPasswordValidator = Member::password_validator();
$this->originalRequirements = Requirements::backend();
Member::set_password_validator(null);
Cookie::set_report_errors(false);
RootURLController::reset();
Translatable::reset();
Versioned::reset();
DataObject::reset();
SiteTree::reset();
Hierarchy::reset();
if (Controller::has_curr()) {
Controller::curr()->setSession(new Session(array()));
}
$this->originalTheme = SSViewer::current_theme();
// Save nested_urls state, so we can restore it later
$this->originalNestedURLsState = SiteTree::nested_urls();
$className = get_class($this);
$fixtureFile = eval("return {$className}::\$fixture_file;");
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
// Set up fixture
if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
if (substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) {
//echo "Re-creating temp database... ";
self::create_temp_db();
//echo "done.\n";
}
singleton('DataObject')->flushCache();
self::empty_temp_db();
foreach ($this->requireDefaultRecordsFrom as $className) {
$instance = singleton($className);
if (method_exists($instance, 'requireDefaultRecords')) {
$instance->requireDefaultRecords();
}
if (method_exists($instance, 'augmentDefaultRecords')) {
$instance->augmentDefaultRecords();
}
}
if ($fixtureFile) {
$fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile);
$i = 0;
foreach ($fixtureFiles as $fixtureFilePath) {
$fixture = new YamlFixture($fixtureFilePath);
$fixture->saveIntoDatabase();
$this->fixtures[] = $fixture;
// backwards compatibility: Load first fixture into $this->fixture
if ($i == 0) {
$this->fixture = $fixture;
}
$i++;
}
}
$this->logInWithPermission("ADMIN");
}
// Set up email
$this->originalMailer = Email::mailer();
$this->mailer = new TestMailer();
Email::set_mailer($this->mailer);
Email::send_all_emails_to(null);
// Preserve memory settings
$this->originalMemoryLimit = ini_get('memory_limit');
}
示例10: add_i18n_javascript
/**
* Add i18n files from the given javascript directory. Sapphire expects that the given directory
* will contain a number of java script files named by language: en_US.js, de_DE.js, etc.
* @param $langDir The javascript lang directory, relative to the site root, e.g., 'sapphire/javascript/lang'
*/
public function add_i18n_javascript($langDir)
{
if (i18n::get_js_i18n()) {
// Include i18n.js even if no languages are found. The fact that
// add_i18n_javascript() was called indicates that the methods in
// here are needed.
$this->javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
if (substr($langDir, -1) != '/') {
$langDir .= '/';
}
$this->javascript($langDir . i18n::default_locale() . '.js');
$this->javascript($langDir . i18n::get_locale() . '.js');
// Stub i18n implementation for when i18n is disabled.
} else {
$this->javascript[SAPPHIRE_DIR . '/javascript/i18nx.js'] = true;
}
}
示例11: setUp
public function setUp()
{
// We cannot run the tests on this abstract class.
if (get_class($this) == "SapphireTest") {
$this->skipTest = true;
}
if ($this->skipTest) {
$this->markTestSkipped(sprintf('Skipping %s ', get_class($this)));
return;
}
// Mark test as being run
$this->originalIsRunningTest = self::$is_running_test;
self::$is_running_test = true;
// i18n needs to be set to the defaults or tests fail
i18n::set_locale(i18n::default_locale());
i18n::config()->date_format = null;
i18n::config()->time_format = null;
// Set default timezone consistently to avoid NZ-specific dependencies
date_default_timezone_set('UTC');
// Remove password validation
$this->originalMemberPasswordValidator = Member::password_validator();
$this->originalRequirements = Requirements::backend();
Member::set_password_validator(null);
Config::inst()->update('Cookie', 'report_errors', false);
if (class_exists('RootURLController')) {
RootURLController::reset();
}
if (class_exists('Translatable')) {
Translatable::reset();
}
Versioned::reset();
DataObject::reset();
if (class_exists('SiteTree')) {
SiteTree::reset();
}
Hierarchy::reset();
if (Controller::has_curr()) {
Controller::curr()->setSession(Injector::inst()->create('Session', array()));
}
Security::$database_is_ready = null;
// Add controller-name auto-routing
Config::inst()->update('Director', 'rules', array('$Controller//$Action/$ID/$OtherID' => '*'));
$fixtureFile = static::get_fixture_file();
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
// Set up email
$this->originalMailer = Email::mailer();
$this->mailer = new TestMailer();
Email::set_mailer($this->mailer);
Config::inst()->remove('Email', 'send_all_emails_to');
// Todo: this could be a special test model
$this->model = DataModel::inst();
// Set up fixture
if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
if (substr(DB::get_conn()->getSelectedDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) {
//echo "Re-creating temp database... ";
self::create_temp_db();
//echo "done.\n";
}
singleton('DataObject')->flushCache();
self::empty_temp_db();
foreach ($this->requireDefaultRecordsFrom as $className) {
$instance = singleton($className);
if (method_exists($instance, 'requireDefaultRecords')) {
$instance->requireDefaultRecords();
}
if (method_exists($instance, 'augmentDefaultRecords')) {
$instance->augmentDefaultRecords();
}
}
if ($fixtureFile) {
$pathForClass = $this->getCurrentAbsolutePath();
$fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile);
$i = 0;
foreach ($fixtureFiles as $fixtureFilePath) {
// Support fixture paths relative to the test class, rather than relative to webroot
// String checking is faster than file_exists() calls.
$isRelativeToFile = strpos('/', $fixtureFilePath) === false || preg_match('/^\\.\\./', $fixtureFilePath);
if ($isRelativeToFile) {
$resolvedPath = realpath($pathForClass . '/' . $fixtureFilePath);
if ($resolvedPath) {
$fixtureFilePath = $resolvedPath;
}
}
$fixture = Injector::inst()->create('YamlFixture', $fixtureFilePath);
$fixture->writeInto($this->getFixtureFactory());
$this->fixtures[] = $fixture;
// backwards compatibility: Load first fixture into $this->fixture
if ($i == 0) {
$this->fixture = $fixture;
}
$i++;
}
}
$this->logInWithPermission("ADMIN");
}
// Preserve memory settings
$this->originalMemoryLimit = ini_get('memory_limit');
// turn off template debugging
Config::inst()->update('SSViewer', 'source_file_comments', false);
// Clear requirements
//.........这里部分代码省略.........
示例12: add_i18n_javascript
/**
* Add i18n files from the given javascript directory. SilverStripe expects that the given directory
* will contain a number of java script files named by language: en_US.js, de_DE.js, etc.
*
* @param String The javascript lang directory, relative to the site root, e.g., 'framework/javascript/lang'
* @param Boolean Return all relative file paths rather than including them in requirements
* @param Boolean Only include language files, not the base libraries
*/
public function add_i18n_javascript($langDir, $return = false, $langOnly = false)
{
$files = array();
if (i18n::get_js_i18n()) {
// Include i18n.js even if no languages are found. The fact that
// add_i18n_javascript() was called indicates that the methods in
// here are needed.
if (!$langOnly) {
$files[] = FRAMEWORK_DIR . '/javascript/i18n.js';
}
if (substr($langDir, -1) != '/') {
$langDir .= '/';
}
$files[] = $langDir . i18n::default_locale() . '.js';
$files[] = $langDir . i18n::get_locale() . '.js';
// Stub i18n implementation for when i18n is disabled.
} else {
if (!$langOnly) {
$files[] = FRAMEWORK_DIR . '/javascript/i18nx.js';
}
}
if ($return) {
return $files;
} else {
foreach ($files as $file) {
$this->javascript($file);
}
}
}
示例13: InvalidArgumentException
/**
* See {@link default_locale()} for usage.
*
*
* @param String $locale
*/
static function set_default_locale($locale)
{
if (!self::validate_locale($locale)) {
throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
}
self::$default_locale = $locale;
}
示例14: process_i18n_javascript
/**
* Automatically includes the necessary lang-files from the module
* according to the locale set in {@link i18n::$current_locale}.
* Assumes that a subfolder /javascript exists relative to the included
* javascript file, with a file named after the locale -
* so usually <mymodule>/javascript/lang/en_US.js.
*/
protected function process_i18n_javascript() {
// ensure to include the i18n base library
if(
count(array_diff_key($this->javascript,$this->blocked))
&& !isset($this->javascript[SAPPHIRE_DIR . '/javascript/i18n.js'])
) {
$this->javascript[THIRDPARTY_DIR . '/prototype.js'] = true;
$this->javascript[SAPPHIRE_DIR . '/javascript/i18n.js'] = true;
}
// include the specific locale and the master locale for each module
foreach(array_diff_key($this->javascript,$this->blocked) as $file => $dummy) {
if(preg_match('/^http[s]?/', $file)) continue;
$absolutePath = Director::baseFolder() . '/' . $file;
$absoluteLangPath = dirname($absolutePath) . '/lang/' . i18n::get_locale() . '.js';
$absoluteDefaultLangPath = dirname($absolutePath) . '/lang/' . i18n::default_locale() . '.js';
foreach(array($absoluteDefaultLangPath, $absoluteLangPath) as $path) {
if(Director::fileExists($path)) {
$langFile = Director::makeRelative($path);
// Remove rogue leading slashes from Director::makeRelative()
$langFile = preg_replace('/^\//', '', $langFile);
$this->javascript[$langFile] = true;
}
}
}
}
示例15: __construct
public function __construct($name = null)
{
$this->currencyLib = new Zend_Currency(null, i18n::default_locale());
parent::__construct($name);
}