本文整理汇总了PHP中Illuminate\Translation\Translator::getLoader方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::getLoader方法的具体用法?PHP Translator::getLoader怎么用?PHP Translator::getLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Translation\Translator
的用法示例。
在下文中一共展示了Translator::getLoader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the command.
*
* @param Filesystem $fileSystem
* @param Application $app
* @param Translator $translator
* @param TranslationRepositoryInterface $repository
* @param Dispatcher $event
*/
public function handle(Filesystem $fileSystem, Application $app, Translator $translator, TranslationRepositoryInterface $repository, Dispatcher $event)
{
$files = $fileSystem->allFiles($app->langPath());
$loader = $translator->getLoader();
/** @var Collection $groups */
$groups = $this->dispatch(new ImportGroupsCommand());
/** @var Collection $languages */
$languages = $this->dispatch(new ImportLanguagesCommand());
foreach ($files as $file) {
/** @var Language $language */
$language = $languages->where('name', $file->getRelativePath())->first();
/** @var Group $group */
$group = $groups->where('name', pathinfo($file)['filename'])->first();
/** @var Collection $translations */
$translations = collect($loader->load($language->name, $group->name));
/**
* Convert all arrays to to json
*/
$translations->transform(function ($value) {
return is_array($value) ? json_encode($value) : $value;
});
/**
* Merge Translations on the database with local translations
*/
$model = $repository->fetch($language->id, $group->id);
$database = $model->lists('value', 'key');
/**
* If translations is an array, process the JSON data and update it
*/
$translations->each(function ($data, $key) use($database, $model) {
/**
* If it's not a json then there is nothing to update
*/
if ($model->isEmpty() or !$this->isJSON($data)) {
return;
}
/**
* Retrieve Json
*/
$decoded = $database->map(function ($value) {
return json_decode($value, true);
});
$value = collect(json_decode($data, true))->merge($decoded->get($key))->toJson();
/**
* Update Translation
*/
$updateCommand = new UpdateTranslationCommand($model->where('key', $key)->first()->id, compact('value'));
$this->dispatch($updateCommand);
});
/**
* First get only new values that are not already on the DB
* Then for each save new Translation on DB
* Save Translations on database
*/
$newItems = $translations->merge($database)->diff($database)->map(function ($value, $key) use($language, $group) {
return $this->dispatch(new CreateTranslationCommand($language->id, $group->id, compact('key', 'value')));
});
/**
* Announce Translations was created
*/
if (!$newItems->isEmpty()) {
$event->fire(new TranslationsWasCreated($newItems));
}
}
}
示例2: getLoader
/**
* Get the language line loader implementation.
*
* @return \Illuminate\Translation\LoaderInterface
* @static
*/
public static function getLoader()
{
return \Illuminate\Translation\Translator::getLoader();
}
示例3: getLanguageFile
private function getLanguageFile($locale, $page)
{
return $this->translator->getLoader()->load($locale, $page);
}