本文整理汇总了PHP中Locale::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getInstance方法的具体用法?PHP Locale::getInstance怎么用?PHP Locale::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::getInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreate
function testCreate()
{
// attempt to create non-existing locale
$locale = Locale::getInstance('enz');
//$this->assertFalse($locale);
// create existing locale
$locale = Locale::getInstance('en');
$this->assertTrue($locale instanceof Locale);
// set as current locale
Locale::setCurrentLocale('en');
$current = Locale::getCurrentLocale();
$this->assertSame($current, $locale);
}
示例2: getUserAddress
private function getUserAddress($data, $prefix)
{
$address = UserAddress::getNewInstance();
$map = array('company' => 'companyName', 'street_address' => 'address1', 'city' => 'city', 'postcode' => 'postalCode', 'state' => 'stateName', 'firstname' => 'firstName', 'lastname' => 'lastName');
foreach ($map as $osc => $lc) {
if (isset($data[$prefix . $osc])) {
$address->{$lc}->set($data[$prefix . $osc]);
}
}
if (!empty($data[$prefix . 'name'])) {
$names = explode(' ', $data[$prefix . 'name'], 2);
$address->firstName->set(array_shift($names));
$address->lastName->set(array_shift($names));
}
if (isset($data['customers_telephone'])) {
$address->phone->set($data['customers_telephone']);
}
if (isset($data[$prefix . 'country'])) {
$country = array_search($data[$prefix . 'country'], Locale::getInstance('en')->info()->getAllCountries());
if (!$country) {
$country = 'US';
}
$address->countryID->set($country);
}
return $address;
}
示例3: loadLocale
private function loadLocale()
{
if (empty($this->locale)) {
ClassLoader::import('library.locale.Locale');
$this->locale = Locale::getInstance($this->localeName);
$this->locale->translationManager()->setCacheFileDir(ClassLoader::getRealPath('storage.language'));
foreach ($this->getConfigContainer()->getLanguageDirectories() as $dir) {
$this->locale->translationManager()->setDefinitionFileDir($dir);
}
$this->locale->translationManager()->setDefinitionFileDir(ClassLoader::getRealPath('storage.language'));
Locale::setCurrentLocale($this->localeName);
$this->loadLanguageFiles();
}
return $this->locale;
}
示例4: initLocales
private function initLocales()
{
ClassLoader::import('library.locale.Locale');
$filter = new ARSelectFilter();
$filter->setOrder(new ARFieldHandle("Language", "position"), ARSelectFilter::ORDER_ASC);
$filter->setCondition(new EqualsCond(new ARFieldHandle("Language", "isEnabled"), 1));
if (count($this->limitToLocales) > 0) {
$z = array();
foreach ($this->limitToLocales as $localeCode) {
$z[] = new EqualsCond(new ARFieldHandle("Language", "ID"), $localeCode);
}
$filter->mergeCondition(new OrChainCondition($z));
// new INCond()
}
$languages = ActiveRecord::getRecordSetArray("Language", $filter);
foreach ($languages as $language) {
$locale = Locale::getInstance($language['ID']);
$locale->translationManager()->setCacheFileDir(ClassLoader::getRealPath('storage.language'));
foreach ($this->application->getConfigContainer()->getLanguageDirectories() as $dir) {
$locale->translationManager()->setDefinitionFileDir($dir);
}
$locale->translationManager()->setDefinitionFileDir(ClassLoader::getRealPath('storage.language'));
$locale->translationManager()->loadFile('backend/Settings');
$this->locales[$language['ID']] = $locale;
}
$this->localeCodes = array_keys($this->locales);
}
示例5: send
public function send()
{
ClassLoader::ignoreMissingClasses();
$this->application->processInstancePlugins('email-prepare-send', $this);
$this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this);
if ($this->template) {
$originalLocale = $this->application->getLocale();
$emailLocale = Locale::getInstance($this->getLocale());
$this->application->setLocale($emailLocale);
$this->application->getLocale()->translationManager()->loadFile('User');
$this->application->loadLanguageFiles();
$smarty = $this->application->getRenderer()->getSmartyInstance();
foreach ($this->values as $key => $value) {
$smarty->assign($key, $value);
}
$router = $this->application->getRouter();
$smarty->assign('html', false);
$smarty->disableTemplateLocator();
$text = $smarty->fetch($this->template);
$smarty->enableTemplateLocator();
$parts = explode("\n", $text, 2);
$this->subject = array_shift($parts);
$this->setText(array_shift($parts));
// fix URLs
$this->text = str_replace('&', '&', $this->text);
if ($this->application->getConfig()->get('HTML_EMAIL')) {
$smarty->assign('html', true);
$html = array_pop(explode("\n", $smarty->fetch($this->template), 2));
$css = new EditedCssFile('email');
$smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode()));
$smarty->assign('messageHtml', $html);
$html = $smarty->fetch($this->getTemplatePath('htmlWrapper'));
$this->setHtml($html);
}
$this->application->setLocale($originalLocale);
}
$this->application->processInstancePlugins('email-before-send', $this);
$this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this);
$this->message->setSubject($this->subject);
if ($this->html) {
preg_match_all('/\\#\\#([_\\-\\.a-zA-Z0-9\\/]+)\\#\\#/msU', $this->html, $matches);
$html = $this->html;
if (!empty($matches[1])) {
foreach ($matches[1] as $match) {
$html = str_replace('##' . $match . '##', $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match)), $html);
}
}
preg_match_all('/src\\=\\"([\\:_\\-\\.a-zA-Z0-9\\/]+)\\"/msU', $this->html, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $match) {
if (substr($match, 0, 4) == 'http') {
if (substr($match, 0, strlen($this->url)) == $this->url) {
$match = substr($match, strlen($this->url));
}
}
if (!substr($match, 0, 4) == 'http') {
$match = $this->message->embed(Swift_Image::fromPath(ClassLoader::getRealPath('public.') . $match));
}
$html = str_replace('src="' . $match . '"', 'src="' . $match . '"', $html);
}
$html = str_replace('src="upload', 'src="' . $this->url . '/upload', $html);
}
$this->message->setBody($html, 'text/html');
}
if ($this->text) {
if (!$this->html) {
$this->message->setBody($this->text, 'text/plain');
} else {
$this->message->addPart($this->text, 'text/plain');
}
}
if (!$this->text && !$this->html) {
return false;
}
try {
$res = $this->swiftInstance->send($this->message);
ClassLoader::ignoreMissingClasses(false);
} catch (Exception $e) {
$this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e));
$this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e));
ClassLoader::ignoreMissingClasses(false);
return false;
}
$this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this);
$this->application->processInstancePlugins('email-after-send', $this);
return $res;
}
示例6: getCurrentLocale
/**
* Gets locale, which is defined as current {@see Locale::setCurrentLocale}
* @return Locale
*/
public static function getCurrentLocale()
{
return Locale::getInstance(self::$currentLocale);
}
示例7: translationDialog
/**
* Displays translation dialog menu for Live Translations
*
* @return ActionResponse
*/
public function translationDialog()
{
$id = $this->request->get('id');
$file = base64_decode($this->request->get('file'));
$translation = $this->locale->translationManager()->get($file, $id);
$defaultTranslation = Locale::getInstance($this->application->getDefaultLanguageCode())->translationManager()->get($file, $id);
$response = new ActionResponse();
$response->set('id', $id);
$response->set('file', $file);
$response->set('translation', $translation);
$response->set('defaultTranslation', $defaultTranslation);
$response->set('language', Language::getInstanceByID($this->locale->getLocaleCode())->toArray());
return $response;
}
示例8: send
public function send()
{
ClassLoader::ignoreMissingClasses();
$this->application->processInstancePlugins('email-prepare-send', $this);
$this->application->processInstancePlugins('email-prepare-send/' . $this->relativeTemplatePath, $this);
if ($this->template) {
$originalLocale = $this->application->getLocale();
$emailLocale = Locale::getInstance($this->getLocale());
$this->application->setLocale($emailLocale);
$this->application->getLocale()->translationManager()->loadFile('User');
$this->application->loadLanguageFiles();
$smarty = $this->application->getRenderer()->getSmartyInstance();
foreach ($this->values as $key => $value) {
$smarty->assign($key, $value);
}
$router = $this->application->getRouter();
$smarty->assign('html', false);
$smarty->disableTemplateLocator();
$text = $smarty->fetch($this->template);
$smarty->enableTemplateLocator();
$parts = explode("\n", $text, 2);
$this->subject = array_shift($parts);
$this->setText(array_shift($parts));
// fix URLs
$this->text = str_replace('&', '&', $this->text);
if ($this->application->getConfig()->get('HTML_EMAIL')) {
$smarty->assign('html', true);
$html = array_pop(explode("\n", $smarty->fetch($this->template), 2));
$css = new EditedCssFile('email');
$smarty->assign('cssStyle', str_replace("\n", ' ', $css->getCode()));
$smarty->assign('messageHtml', $html);
$html = $smarty->fetch($this->getTemplatePath('htmlWrapper'));
$this->setHtml($html);
}
$this->application->setLocale($originalLocale);
}
$this->application->processInstancePlugins('email-before-send', $this);
$this->application->processInstancePlugins('email-before-send/' . $this->relativeTemplatePath, $this);
$this->message->setSubject($this->subject);
if ($this->html) {
$this->message->setBody($this->html, 'text/html');
}
if ($this->text) {
if (!$this->html) {
$this->message->setBody($this->text, 'text/plain');
} else {
$this->message->addPart($this->text, 'text/plain');
}
}
if (!$this->text && !$this->html) {
return false;
}
try {
$res = $this->swiftInstance->send($this->message);
ClassLoader::ignoreMissingClasses(false);
} catch (Exception $e) {
$this->application->processInstancePlugins('email-fail-send/' . $this->relativeTemplatePath, $this, array('exception' => $e));
$this->application->processInstancePlugins('email-fail-send', $this, array('exception' => $e));
ClassLoader::ignoreMissingClasses(false);
return false;
}
$this->application->processInstancePlugins('email-after-send/' . $this->relativeTemplatePath, $this);
$this->application->processInstancePlugins('email-after-send', $this);
return $res;
}