当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::langPath方法代码示例

本文整理汇总了PHP中Illuminate\Foundation\Application::langPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::langPath方法的具体用法?PHP Application::langPath怎么用?PHP Application::langPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Foundation\Application的用法示例。


在下文中一共展示了Application::langPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Execute the command.
  *
  * @param TranslationRepositoryInterface $repository
  * @param Filesystem $fileSystem
  * @param Application $app
  */
 public function handle(TranslationRepositoryInterface $repository, Filesystem $fileSystem, Application $app)
 {
     /** @var Collection $translations */
     $translations = $repository->all()->load('groups', 'language');
     /**
      * Execute operation for each language within the database
      */
     $translations->groupBy('language.name')->map(function ($translations, $language) use($app, $fileSystem) {
         /**
          * Divide into groups
          */
         $groups = $translations->map(function ($translation) {
             return $translation->groups->pluck('name');
         })->collapse();
         /**
          * For each group create a separated file
          */
         $groups->each(function ($group) use($translations, $language, $app, $fileSystem) {
             /**
              * Filter Trough to get only translations that belongs to this group
              */
             $content = $translations->filter(function ($translation) use($group) {
                 return !$translation->groups->where('name', $group)->isEmpty();
             })->lists('value', 'key')->toArray();
             /**
              * Generate popper output
              */
             $output = "<?php\n\nreturn " . var_export($content, true) . ";\n";
             $directory = $app->langPath() . '/' . $language;
             $file = $directory . '/' . $group . '.php';
             /**
              * if Directory doesnt exist then create it
              */
             if (!$fileSystem->exists($directory)) {
                 $fileSystem->makeDirectory($app->langPath() . '/' . $language);
             }
             /**
              * if File already exist delete it.
              */
             if ($fileSystem->exists($file)) {
                 $fileSystem->delete($file);
             }
             /**
              * Write file
              */
             $fileSystem->put($file, $output);
         });
     });
 }
开发者ID:SkysoulDesign,项目名称:TempArk,代码行数:56,代码来源:ExportTranslationCommand.php

示例2: handle

 /**
  * Execute the command.
  *
  * @param Filesystem $fileSystem
  * @param Application $app
  * @param TranslationRepositoryInterface $repository
  * @param Dispatcher $event
  * @return Collection of Group
  */
 public function handle(Filesystem $fileSystem, Application $app, TranslationRepositoryInterface $repository, Dispatcher $event)
 {
     $files = $fileSystem->allFiles($app->langPath());
     /**
      * Retrieves all local languages
      */
     $languages = collect($files)->transform(function ($file) {
         return $file->getRelativePath();
     })->unique();
     /**
      * Save Database instance with all languages
      */
     $database = $repository->languages();
     /**
      * List Only names
      */
     $names = $database->pluck('name');
     /**
      * Create New Language for those which has been set locally
      * but was not present yet on the database
      */
     $newLanguages = $languages->merge($names)->diff($names)->map(function ($name) {
         return $this->dispatch(new CreateLanguageCommand($name));
     });
     /**
      * Announce LanguagesWasCreated
      */
     if (!$newLanguages->isEmpty()) {
         $event->fire(new LanguagesWasCreated($newLanguages));
     }
     /**
      * Returns All languages
      */
     return $database->merge($newLanguages);
 }
开发者ID:SkysoulDesign,项目名称:TempArk,代码行数:44,代码来源:ImportLanguagesCommand.php

示例3: exportTranslations

 public function exportTranslations($group)
 {
     if ($group == '*') {
         return $this->exportAllTranslations();
     }
     $g = Group::find($group);
     if (!in_array($g->label, $this->config['exclude_groups'])) {
         $tree = $this->makeTree(Translation::where('group_id', $g->id)->whereNotNull('value')->get());
         foreach ($tree as $locale => $groups) {
             $filename = $g->label;
             if (isset($groups[$g->label])) {
                 if (str_contains($g->label, '/')) {
                     $groupPath = $g->label;
                     $filename = basename($groupPath);
                     $folder = dirname($groupPath);
                     $directoryPath = $this->app->langPath() . '/' . $locale . '/' . $folder;
                     if (!$this->files->exists($directoryPath)) {
                         $this->files->makeDirectory($directoryPath, 493, true, true);
                     }
                     $path = $this->app->langPath() . "/{$locale}/{$folder}/{$filename}.php";
                 } else {
                     $path = $this->app->langPath() . "/{$locale}/{$filename}.php";
                 }
                 $translations = $groups[$g->label];
                 $path = $this->app->langPath() . '/' . $locale . '/' . $g->label . '.php';
                 $output = "<?php\n\nreturn " . var_export($translations, true) . ";\n";
                 $this->files->put($path, $output);
             }
         }
         Translation::where('group_id', $g->id)->whereNotNull('value')->update(array('status' => Translation::STATUS_SAVED));
     }
 }
开发者ID:camdjn,项目名称:laravel-translation-manager,代码行数:32,代码来源:Manager.php

示例4: addLocale

 public function addLocale($locale)
 {
     $localeDir = $this->app->langPath() . '/' . $locale;
     $this->ignoreLocales = array_diff($this->ignoreLocales, [$locale]);
     $this->saveIgnoredLocales();
     $this->ignoreLocales = $this->getIgnoredLocales();
     if (!$this->files->exists($localeDir) || !$this->files->isDirectory($localeDir)) {
         return $this->files->makeDirectory($localeDir);
     }
     return true;
 }
开发者ID:txandy,项目名称:laravel-translation-manager,代码行数:11,代码来源:Manager.php

示例5: getPath

 protected function getPath($group, $locale)
 {
     // Is module?
     if (strpos($group, '::')) {
         $parts = explode('::', $group);
         $path = $this->app->path() . '/Modules/' . ucfirst($parts[0]) . '/lang/' . $locale . '/' . $parts[1] . '.php';
     } else {
         $path = $this->app->langPath() . '/' . $locale . '/' . $group . '.php';
     }
     return $path;
 }
开发者ID:spajz,项目名称:laravel-translation-manager,代码行数:11,代码来源:Manager.php

示例6: getLocales

 public function getLocales()
 {
     if (empty($this->locales)) {
         $locales = array_merge([config('app.locale')], Translation::groupBy('locale')->lists('locale')->all());
         foreach ($this->files->directories($this->app->langPath()) as $localeDir) {
             $locales[] = $this->files->name($localeDir);
         }
         $this->locales = array_unique($locales);
         sort($this->locales);
     }
     return $this->locales;
 }
开发者ID:elephantux,项目名称:laravel-translation-manager,代码行数:12,代码来源:Manager.php

示例7: exportTranslations

 public function exportTranslations($group)
 {
     if (!in_array($group, $this->config['exclude_groups'])) {
         if ($group == '*') {
             return $this->exportAllTranslations();
         }
         $tree = $this->makeTree(Translation::where('group', $group)->whereNotNull('value')->get());
         foreach ($tree as $locale => $groups) {
             if (isset($groups[$group])) {
                 $translations = $groups[$group];
                 $path = $this->app->langPath() . '/' . $locale . '/' . $group . '.php';
                 $output = "<?php\n\nreturn " . var_export($translations, true) . ";\n";
                 $this->files->put($path, $output);
             }
         }
         Translation::where('group', $group)->whereNotNull('value')->update(array('status' => Translation::STATUS_SAVED));
     }
 }
开发者ID:barryvdh,项目名称:laravel-translation-manager,代码行数:18,代码来源:Manager.php

示例8: langPath

 /**
  * Get the path to the language files.
  *
  * @return string 
  * @static 
  */
 public static function langPath()
 {
     return \Illuminate\Foundation\Application::langPath();
 }
开发者ID:satriashp,项目名称:tour,代码行数:10,代码来源:_ide_helper.php

示例9: exportTranslations

    public function exportTranslations($group, $recursing = 0)
    {
        // TODO: clean up this recursion crap
        // this can come from the command line
        $ltm_translations = $this->getTranslationsTableName();
        if (!$recursing) {
            $this->clearErrors();
            $group = self::fixGroup($group);
        }
        if ($group && $group !== '*') {
            $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1");
        } elseif (!$recursing) {
            $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1 AND `group` = ?", [$group]);
        }
        $inDatabasePublishing = $this->inDatabasePublishing();
        if ($inDatabasePublishing < 3 && $inDatabasePublishing && ($inDatabasePublishing < 2 || !$recursing)) {
            if ($group && $group !== '*') {
                $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?) AND `group` = ?
SQL
, [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED, $group]);
                $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->where('group', '=', $group)->get(['group', 'key', 'locale', 'saved_value']);
            } else {
                $this->getConnection()->affectingStatement(<<<SQL
UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?)
SQL
, [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED]);
                $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->get(['group', 'key', 'locale', 'saved_value']);
            }
            /* @var $translations Collection */
            $this->clearCache($group);
            $this->clearUsageCache(false, $group);
            $translations->each(function ($tr) {
                $this->cacheTranslation($tr->group . '.' . $tr->key, $tr->saved_value, $tr->locale);
            });
        }
        if (!$inDatabasePublishing || $inDatabasePublishing === 2 || $inDatabasePublishing === 3) {
            if (!in_array($group, $this->config(self::EXCLUDE_GROUPS_KEY))) {
                if ($group == '*') {
                    $this->exportAllTranslations(1);
                }
                if ($inDatabasePublishing !== 3) {
                    $this->clearCache($group);
                    $this->clearUsageCache(false, $group);
                }
                $tree = $this->makeTree($this->translation->where('group', $group)->whereNotNull('value')->orderby('key')->get());
                $configRewriter = new TranslationFileRewriter();
                $exportOptions = array_key_exists('export_format', $this->config()) ? TranslationFileRewriter::optionFlags($this->config('export_format')) : null;
                // Laravel 5.1
                $base_path = $this->app->basePath();
                $pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '5');
                $zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->langPath(), 0, -4));
                // Laravel 4.2
                //$base_path = base_path();
                //$pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '4');
                //$zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->make('path').'/lang', 0, -4));
                if (mb_substr($zipRoot, -1) === '/') {
                    $zipRoot = substr($zipRoot, 0, -1);
                }
                foreach ($tree as $locale => $groups) {
                    if (isset($groups[$group])) {
                        $translations = $groups[$group];
                        // use the new path mapping
                        $computedPath = $base_path . $pathTemplateResolver->groupFilePath($group, $locale);
                        $path = $computedPath;
                        if ($path) {
                            $configRewriter->parseSource($this->files->exists($path) ? $this->files->get($path) : '');
                            $output = $configRewriter->formatForExport($translations, $exportOptions);
                            if ($this->zipExporting) {
                                $pathPrefix = mb_substr($path, 0, mb_strlen($zipRoot));
                                $filePathName = $pathPrefix === $zipRoot ? mb_substr($path, mb_strlen($zipRoot)) : $path;
                                //$this->makeDirPath($filePathName);
                                $this->zipExporting->addFromString($filePathName, $output);
                            } else {
                                try {
                                    $this->makeDirPath($path);
                                    if (($result = $this->files->put($path, $output)) === false) {
                                        $this->errors[] = "Failed to write to {$path}";
                                    }
                                } catch (Exception $e) {
                                    $this->errors[] = $e->getMessage();
                                }
                            }
                        }
                    }
                }
                if (!$inDatabasePublishing) {
                    $this->translation->where('group', $group)->update(array('status' => Translation::STATUS_SAVED, 'saved_value' => new Expression('value')));
                }
            }
        }
    }
开发者ID:mean-cj,项目名称:laravel-translation-manager,代码行数:92,代码来源:Manager.php

示例10: 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));
         }
     }
 }
开发者ID:SkysoulDesign,项目名称:TempArk,代码行数:74,代码来源:ImportTranslationCommand.php

示例11: registerTranslation

 /**
  * Register the aliases from this module.
  */
 protected function registerTranslation()
 {
     $langPath = $this->app->langPath() . '/' . $this->getPathName();
     $this->loadTranslationsFrom(is_dir($langPath) ? $langPath : $this->manifest->getPath() . '/Resources/lang', $this->getSlugName());
 }
开发者ID:jooorooo,项目名称:modulator,代码行数:8,代码来源:Module.php


注:本文中的Illuminate\Foundation\Application::langPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。