本文整理汇总了PHP中i18n::validate_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::validate_locale方法的具体用法?PHP i18n::validate_locale怎么用?PHP i18n::validate_locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类i18n
的用法示例。
在下文中一共展示了i18n::validate_locale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateEditForm
public function updateEditForm(Form $form)
{
$locale = isset($_REQUEST['locale']) ? $_REQUEST['locale'] : $_REQUEST['Locale'];
if (!empty($locale) && i18n::validate_locale($locale) && singleton('SiteConfig')->has_extension('Translatable') && (Translatable::get_allowed_locales() === null || in_array($locale, (array) Translatable::get_allowed_locales(), false)) && $locale != Translatable::get_current_locale()) {
$orig = Translatable::get_current_locale();
Translatable::set_current_locale($locale);
$formAction = $form->FormAction();
$form->setFormAction($formAction);
Translatable::set_current_locale($orig);
}
}
示例2: set_locales
/**
* Explicitly set the locales that should be translated.
*
* @example
* <code>
* // Set locales to en_US and fr_FR
* TranslatableDataObject::set_locales(array('en_US', 'fr_FR'));
* </code>
*
* Defaults to `null`. In this case, locales are being taken from
* Translatable::get_allowed_locales or Translatable::get_existing_content_languages
*
* @param array|null $locales an array of locales or null
* @deprecated 2.0 use YAML config `locales` instead
*/
public static function set_locales($locales)
{
if (is_array($locales)) {
$list = array();
foreach ($locales as $locale) {
if (i18n::validate_locale($locale)) {
$list[] = $locale;
}
}
$list = array_unique($list);
Config::inst()->update('TranslatableDataObject', 'locales', empty($list) ? null : $list);
} else {
Config::inst()->update('TranslatableDataObject', 'locales', null);
}
}
示例3: testValidateLocale
public function testValidateLocale()
{
$this->assertTrue(i18n::validate_locale('en_US'), 'Known locale in underscore format is valid');
$this->assertTrue(i18n::validate_locale('en-US'), 'Known locale in dash format is valid');
$this->assertFalse(i18n::validate_locale('en'), 'Short lang format is not valid');
$this->assertFalse(i18n::validate_locale('xx_XX'), 'Unknown locale in correct format is not valid');
$this->assertFalse(i18n::validate_locale(''), 'Empty string is not valid');
}
示例4: hasTranslation
/**
* Returns TRUE if the current record has a translation in this language.
* Use {@link getTranslation()} to get the actual translated record from
* the database.
*
* @param string $locale
* @return boolean
*/
function hasTranslation($locale)
{
if ($locale && !i18n::validate_locale($locale)) {
throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
}
return $this->owner->Locale == $locale || array_search($locale, $this->getTranslatedLocales()) !== false;
}
示例5: valid_prefix
/**
* Is the prefix a valid locale? (@see alternateGetByLink)
*
* @param string $prefix
* @return boolean
*/
public static function valid_prefix($prefix)
{
// is this part of the prefix map if there is one?
if (!empty(self::$locale_prefix_map)) {
return in_array($prefix, self::$locale_prefix_map);
}
// is this part of the allowed languages, if there are any
$alowed_locales = Translatable::get_allowed_locales();
if (!empty($alowed_locales)) {
return in_array($prefix, $alowed_locales);
}
// is this a valid locale anyway?
return i18n::validate_locale($prefix);
}
示例6: set_locales
/**
* Explicitly set the locales that should be translated.
*
* @example
* <code>
* // Set locales to en_US and fr_FR
* TranslatableDataObject::set_locales(array('en_US', 'fr_FR'));
* </code>
*
* Defaults to `null`. In this case, locales are being taken from
* Translatable::get_allowed_locales or Translatable::get_existing_content_languages
*
* @param array $locales an array of locales or null
*/
public static function set_locales($locales)
{
if (is_array($locales)) {
foreach ($locales as $locale) {
if (i18n::validate_locale($locale)) {
if (!is_array(self::$locales)) {
self::$locales = array();
}
if (array_search($locale, self::$locales) === false) {
self::$locales[] = $locale;
}
}
}
} else {
self::$locales = null;
}
}
示例7: handleRequest
/**
* This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to
* fall over to a child controller in order to provide functionality for nested URLs.
*
* @param SS_HTTPRequest $request
* @param DataModel $model
* @return SS_HTTPResponse
* @throws SS_HTTPResponse_Exception
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
$child = null;
$action = $request->param('Action');
$this->setDataModel($model);
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
// nested URL.
if ($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) {
// See ModelAdController->getNestedController() for similar logic
if (class_exists('Translatable')) {
Translatable::disable_locale_filter();
}
// look for a page with this URLSegment
$child = $this->model->SiteTree->filter(array('ParentID' => $this->ID, 'URLSegment' => rawurlencode($action)))->first();
if (class_exists('Translatable')) {
Translatable::enable_locale_filter();
}
}
// we found a page with this URLSegment.
if ($child) {
$request->shiftAllParams();
$request->shift();
$response = ModelAsController::controller_for($child)->handleRequest($request, $model);
} else {
// If a specific locale is requested, and it doesn't match the page found by URLSegment,
// look for a translation and redirect (see #5001). Only happens on the last child in
// a potentially nested URL chain.
if (class_exists('Translatable')) {
$locale = $request->getVar('locale');
if ($locale && i18n::validate_locale($locale) && $this->dataRecord && $this->dataRecord->Locale != $locale) {
$translation = $this->dataRecord->getTranslation($locale);
if ($translation) {
$response = new SS_HTTPResponse();
$response->redirect($translation->Link(), 301);
throw new SS_HTTPResponse_Exception($response);
}
}
}
Director::set_current_page($this->data());
try {
$response = parent::handleRequest($request, $model);
Director::set_current_page(null);
} catch (SS_HTTPResponse_Exception $e) {
$this->popCurrent();
Director::set_current_page(null);
throw $e;
}
}
return $response;
}