Comments (4)
yes, missing point
from translation.
Implementation, in case somebody need it as me.
`<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ExportResourceCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'trans:export {--group=} {--lang=} {--list} {--test}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Export database translations back to file system';
public function __construct()
{
parent::__construct();
}
private function listFiles()
{
foreach(RESOURCE_FILES as $key => $value)
{
$this->info($key . ' - '. $value);
}
}
private function makeResourseFile($group, $lang = null)
{
$supported_locales = !empty($lang)?[$lang]:config('app.support_local');
foreach($supported_locales as $locale) {
$dir = $locale == 'cn' ? 'zh-CN' : $locale;
$file_name = base_path() . '/resources/lang/'.$dir.'/'.$group.'.php';
$f = fopen($file_name, "w+") or die("Unable to open file!");
fwrite($f, "<?php\n");
fwrite($f, "\n");
fwrite($f, "return [\n");
DB::table('translator_translations')->where(['locale' => $locale, 'group' => $group])->orderBy('item', 'asc')->each(function($row) use (&$f) {
fwrite($f, sprintf("'%s' => '%s',\n", $row->item, $row->text));
});
fwrite($f, "];\n");
fclose($f);
}
}
private function testResourseFile($group, $lang = null)
{
$supported_locales = !empty($lang)?[$lang]:config('app.support_local');
foreach($supported_locales as $locale) {
DB::table('translator_translations')->where(['locale' => $lang, 'group' => $group])->orderBy('item', 'desc')->each(function($row) use (&$f) {
$this->info(sprintf("'%s' => '%s',\n", $row->item, $row->text));
});
}
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
try {
$list = $this->option('list');
if (!empty($list)) {
$this->listFiles();
return;
}
$lang = $this->option('lang');
$group = $this->option('group');
if (!empty($group)) {
$do_test = $this->option('test');
if (!empty($do_test)) {
$this->testResourseFile($group, $lang);
} else {
$this->makeResourseFile($group, $lang);
}
} else {
$this->info('You should specify group name first. Use trans:export --list to see available groups');
}
} catch (\Exception $e) {
\Log::error($e->getMessage());
$this->error($e->getMessage());
}
}
}`
from translation.
@1dnmr Can you write full code and document how to use it please?
from translation.
@AnasSafi all code is above. You need create new command: php artisan make:command and paste this code. Then use it like described above: trans:export {--group=} {--lang=} {--list} {--test}
from translation.
Related Issues (20)
- typo in readme
- Database schema: Connection
- After integration -> Unittest fails: Foreign Constraint HOT 3
- Mysql syntax error during migration. code: 1059 HOT 1
- Support for Laravel 6.0 HOT 1
- Change database structure to allow extra unique index HOT 1
- Set different tables names HOT 1
- Overriding current locale to fetch localized model attributes in specific language HOT 1
- Setting non-translatable raw attributes breaks translation
- translator:load throws db integrity error HOT 1
- Where do I find example codes ?
- How can I delete a language ?
- Browser's Locale: add Region
- Support for Laravel 7.0 ? HOT 3
- method isLocked() doesnot exit when use update translation
- array_replace_recursive(): Argument #1 is not an array HOT 5
- Migrations not publishing
- Support for Laravel 8.0? HOT 5
- not supported with url
- anyone continued this in other repo?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from translation.