本文整理汇总了PHP中Illuminate\Support\Facades\Lang::getLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Lang::getLocale方法的具体用法?PHP Lang::getLocale怎么用?PHP Lang::getLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Lang
的用法示例。
在下文中一共展示了Lang::getLocale方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saving
/**
* Save separately the model attributes and polyglot ones
*
* @param Polyglot $model
*
* @return boolean|null
*/
public function saving(Polyglot $model)
{
// Extract polyglot attributes
$translated = $this->extractTranslatedAttributes($model);
// If no localized attributes, continue
if (empty($translated)) {
return true;
}
// Save new model
if (!$model->exists) {
$model->save();
}
// Get the current lang and Lang model
$lang = array_get($translated, 'lang', Lang::getLocale());
$langModel = $model->{$lang};
$translated['lang'] = $lang;
// If no Lang model or the fallback was returned, create a new one
if (!$langModel || $langModel->lang !== $lang) {
$langModel = $model->getLangClass();
$langModel = new $langModel($translated);
$model->translations()->save($langModel);
$model->setRelation($lang, $langModel);
}
$langModel->fill($translated);
// Save and update model timestamp
if ($model->exists && $model->timestamps && $langModel->getDirty()) {
$time = $model->freshTimestamp();
$model->setUpdatedAt($time);
}
if ($model->save() && $langModel->save()) {
return true;
}
}
示例2: __construct
/**
* BelongToLang constructor.
*
* @param Builder $query
* @param Eloquent $parent
* @param string $foreignKey
* @param string $otherKey
* @param string $langKey
* @param string $relation
* @param null $lang
* @param null $fallback
*/
public function __construct(Builder $query, Eloquent $parent, $foreignKey, $otherKey, $langKey, $relation, $lang = null, $fallback = null)
{
$this->lang = $lang ?: Lang::getLocale();
$this->fallback = $fallback ?: Lang::getFallback();
$this->langKey = $langKey ?: 'lang';
$this->fallbackQuery = clone $query;
parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB') . '/' . Lang::get('routes.services'), date('c', time()), 'monthly', '1');
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB') . '/' . Lang::get('routes.seo'), date('c', time()), 'monthly', '1');
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB') . '/' . Lang::get('routes.design'), date('c', time()), 'monthly', '1');
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB') . '/' . Lang::get('routes.programming'), date('c', time()), 'monthly', '1');
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB') . '/' . Lang::get('routes.contacts'), date('c', time()), 'monthly', '1');
Sitemap::addTag('http://' . env(strtoupper(Lang::getLocale()) . '_WEB'), date('c', time()), 'monthly', '1');
return Sitemap::render();
}
示例4: lang
/**
* If using the return method, it will return an array of the variable
*/
function lang($text = false, $vars = null, $value = null, $group = null, $locale = null, $force_add = false)
{
$original_locale = Lang::getLocale();
$params['value'] = $value ? $value : 0;
$params['vars'] = $vars ? $vars : [];
$params['locale'] = $locale ? $locale : $original_locale;
$params['group'] = $group ? $group : 'general';
$params['dynamic'] = false;
if (preg_match('/dynamic_/', $params['group'])) {
$params['group'] = preg_replace('/dynamic_/', '', $params['group']);
$params['dynamic'] = true;
}
$hash = md5($text) . sha1($text);
$file_namespace = 'dbtranslator';
if (preg_match('/\\|/', $text)) {
$choose = true;
} else {
$choose = false;
}
$config = config('db-translator');
/**
* Before anything lets change the locale to the intl locale
*/
App::setLocale($params['locale']);
/**
* This will check the existence of the translation on the locale given, not the default
*/
if (!$force_add) {
if (Lang::has($file_namespace . '::' . $params['group'] . '.' . $hash)) {
if ($choose) {
$text = trans_choice($file_namespace . '::' . $params['group'] . '.' . $hash, $params['value'], $params['vars']);
App::setLocale($original_locale);
return $text;
} else {
$text = trans($file_namespace . '::' . $params['group'] . '.' . $hash, $params['vars']);
App::setLocale($original_locale);
return $text;
}
} else {
/**
* If we are using the database translations
*/
if ($config['use_database']) {
if (!Intl::whereText($text)->whereGroup($params['group'])->get()->count()) {
$intl = new Intl();
$intl->text = $text;
$intl->group = $params['group'];
$intl->md5sha1 = $hash;
$intl->dynamic = $params['dynamic'];
$intl->save();
}
} else {
/**
* first we will check if the translation exists under the fallback language
*/
App::setLocale($config['default_locale']);
if (!Lang::has($file_namespace . '::' . $params['group'] . '.' . $hash)) {
// if we don't find it, we should include the file for the original locale
// change it with the new array, and save it.
/**
* Determine if the file exists
*/
if (Storage::disk($config['storage_driver'])->exists($config['default_locale'] . '/' . $params['group'] . '.php')) {
$lang_array = (require base_path('resources/lang/vendor/dbtranslator/' . $config['default_locale'] . '/' . $params['group'] . '.php'));
if (!isset($lang_array[$hash])) {
$lang_array[$hash] = $text;
$file = "<?php\n return [\r\n";
foreach ($lang_array as $k => $v) {
$file .= " \"" . $k . "\" => \"" . str_replace('"', '\\"', $v) . "\",\r\n";
}
$file .= "];";
Storage::disk($config['storage_driver'])->put($config['default_locale'] . '/' . $params['group'] . '.php', $file);
}
} else {
$file = "<?php\n return [\r\n";
$file .= " \"" . $hash . "\" => \"" . str_replace('"', '\\"', $text) . "\",\r\n";
$file .= "];";
Storage::disk($config['storage_driver'])->put($config['default_locale'] . '/' . $params['group'] . '.php', $file);
}
}
App::setLocale($params['locale']);
}
// now we will process the string
if ($choose) {
$params['vars']['count'] = $params['value'];
$ms = new MessageSelector();
$text = $ms->choose($text, $params['value'], $params['locale']);
$params['vars'] = (new Collection($params['vars']))->sortBy(function ($value, $key) {
return mb_strlen($key) * -1;
});
foreach ($params['vars'] as $key => $value) {
$text = str_replace(':' . $key, $value, $text);
}
App::setLocale($original_locale);
return $text;
} else {
if (count($params['vars'])) {
//.........这里部分代码省略.........
示例5: scopeLocaled
public function scopeLocaled($query)
{
$query->where('locale', '=', Lang::getLocale());
}
示例6: getCategories
public static function getCategories()
{
$posts = Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->lists('id');
$categories = Category::whereIn('post_id', $posts)->lists('name');
return array_count_values($categories);
}
示例7: news
public static function news()
{
return Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->orderBy('created_at', 'DESC')->take(3)->get();
}
示例8: administrationAjaxHandler
/**
* Administration Ajax Handler
* @param Request $request
* @return mixed
* @author Vini Dubey
*/
public function administrationAjaxHandler(Request $request)
{
$inputData = $request->input();
$method = $inputData['method'];
$ObjLanguageModel = Languages::getInstance();
$ObjLocationModel = Location::getInstance();
$ObjLanguageValuesModel = LanguageValues::getInstance();
switch ($method) {
case 'manageLanguage':
$available_languages = $ObjLanguageModel->getAvailableLanguageDetails();
return Datatables::of($available_languages)->addColumn('action', function ($available_languages) {
return '<div role="group" class="btn-group ">
<button aria-expanded="false" data-toggle="dropdown"
class="btn btn-default dropdown-toggle" type="button">
<i class="fa fa-cog"></i>
<span class="caret"></span>
</button>
<ul role="menu" class="dropdown-menu">
<li><a href="/admin/edit-language/' . $available_languages->lang_id . '""><i
class="fa fa-pencil"></i> ' . trans('message.langedit') . '</a>
</li>
<li><a href="/admin/edit-language/' . $available_languages->lang_id . '""><i
class="fa fa-pencil"></i> ' . trans('message.langexport') . '</a>
</li>
</ul>
</div>
<span class="tooltips" title="Delete Language Details." data-placement="top"> <a href="#" data-cid="' . $available_languages->lang_id . '" class="btn btn-danger delete-language" style="margin-left: 10%;">
<i class="fa fa-trash-o"></i>
</a>
</span>';
})->addColumn('status', function ($available_languages) {
$button = '<td style="text-align: center">';
$button .= '<button class="btn ' . ($available_languages->status == 1 ? "btn-success" : "btn-danger") . ' language-status" data-id="' . $available_languages->lang_id . '">' . ($available_languages->status == 1 ? trans('message.langactive') : trans('message.langinactive')) . ' </button>';
$button .= '</td>';
return $button;
})->addColumn('Add Langauge', function ($available_languages) {
return '<a href="/admin/multi-lang-text/' . $available_languages->lang_code . '">Add Converted Langauge Variables</a>';
})->make();
break;
case 'changeLanguageStatus':
$userId = $inputData['UserId'];
$where = ['rawQuery' => 'lang_id = ?', 'bindParams' => [$userId]];
$dataToUpdate['status'] = $inputData['status'];
$updateResult = $ObjLanguageModel->updateLanguageStatus($dataToUpdate, $where);
if ($updateResult == 1) {
echo json_encode(['status' => 'success', 'msg' => 'Status has been changed.']);
} else {
echo json_encode(['status' => 'error', 'msg' => 'Something went wrong, please reload the page and try again.']);
}
break;
case 'deleteLanguageStatus':
$userId = $inputData['UserId'];
$where = ['rawQuery' => 'lang_id = ?', 'bindParams' => [$userId]];
$deleteStatus = $ObjLanguageModel->deleteLanguage($where);
if ($deleteStatus) {
echo json_encode(['status' => 'success', 'msg' => 'Language Deleted']);
} else {
echo json_encode(['status' => 'error', 'msg' => 'Something went wrong, please reload the page and try again . ']);
}
break;
case 'manageLanguageValue':
$manage_language_value = $ObjLanguageValuesModel->getLanguageValueDetails();
return Datatables::of($manage_language_value)->addColumn('action', function ($manage_language_value) {
return '<div role="group" class="btn-group ">
<button aria-expanded="false" data-toggle="dropdown"
class="btn btn-default dropdown-toggle" type="button">
<i class="fa fa-cog"></i>
<span class="caret"></span>
</button>
<ul role="menu" class="dropdown-menu">
<li><a href="/admin/edit-language-value/' . $manage_language_value->lang_value_id . '""><i
class="fa fa-pencil"></i> ' . trans('message.langedit') . '</a>
</li>
</ul>
</div>
<span class="tooltips" title="Delete Language Details." data-placement="top"> <a href="#" data-cid="' . $manage_language_value->lang_value_id . '" class="btn btn-danger delete-language" style="margin-left: 10%;">
<i class="fa fa-trash-o"></i>
</a>
</span>';
})->addColumn('check', function ($manage_language_value) {
return '<input id="' . $manage_language_value->lang_value_id . '" class="questionCheckBox" type="checkbox" />';
})->make();
break;
case 'multi-lang-text':
$ObjLanguageValue = LanguageValues::getInstance();
$lcode = Lang::getLocale();
if ($lcode == 'en') {
$lcode = 'value';
}
$selectColumn = ['language_values.*'];
$langDetail = $ObjLanguageValue->getAllLanguageVariable($selectColumn, $lcode);
//.........这里部分代码省略.........
开发者ID:sumitglobussoft,项目名称:Flash-Sale-Ecommerce-Portal-PHP,代码行数:101,代码来源:AdministrationController.php
示例9: scopeWithLang
/**
* Localize a "with" method
*
* @param Query $query
* @param string $relations ...
*
* @return Query
*/
public function scopeWithLang()
{
$relations = func_get_args();
$query = array_shift($relations);
if (empty($relations)) {
$relations = array(Lang::getLocale());
}
return $query->with($relations);
}
示例10: build
/**
* @param $category
* @param $page
* @return $this
*/
public function build($category, $page)
{
$morePage = 0;
$posts = Post::get($category, $page);
if ($category == null) {
if (Config::get('app.max_post_per_page') * $page < Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
$morePage = 1;
}
} else {
$ids = Category::where('name', '=', $category)->lists('post_id');
if (Config::get('app.max_post_per_page') * $page < Post::whereIn('id', $ids)->where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
$morePage = 1;
}
}
$this->statistics->incrementPage('welcome');
return view('welcome')->with(array('posts' => $posts, 'page' => $page, 'category' => $category, 'morePage' => $morePage));
}
示例11: show
/**
* Return the mail as html.
* @return string
*/
public function show()
{
// Set the email's locale:
$currentLocale = Lang::getLocale();
$newLocale = $this->locale ?: Lang::getLocale();
Lang::setLocale($newLocale);
// Generate HTML:
$html = View::make($this->view, $this->data)->render();
$css = File::get($this->cssFile);
$inliner = new CssInline($html, $css);
$body = $inliner->convert();
// Return App locale to former value:
Lang::setLocale($currentLocale);
return $body;
}