Locale unification part 2 (make PHP handle all locale gen/import).
This commit is contained in:
parent
bf90348788
commit
b02bf1a3ed
|
@ -70,17 +70,13 @@ jobs:
|
|||
if: github.event_name == 'push' || github.event_name == 'schedule'
|
||||
run: |
|
||||
rm -rf resources/locale/compiled
|
||||
rm -rf resources/locale/compiled_js
|
||||
rm -rf resources/locale/*.UTF-8
|
||||
rm -rf resources/locale/translations.json
|
||||
mkdir -p resources/locale/compiled
|
||||
|
||||
- name: Generate new translations from existing code.
|
||||
if: github.event_name == 'push' || github.event_name == 'schedule'
|
||||
run: |
|
||||
cd frontend
|
||||
npm ci
|
||||
npm run generate-locales
|
||||
bin/console locale:generate
|
||||
run: bin/console locale:generate
|
||||
|
||||
- name: Pull latest translations.
|
||||
if: github.event_name == 'push' || github.event_name == 'schedule'
|
||||
|
@ -103,7 +99,6 @@ jobs:
|
|||
|
||||
cd frontend
|
||||
npm ci
|
||||
npm run import-locales
|
||||
npm run build
|
||||
|
||||
- name: Build OpenAPI Docs
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,12 +2,10 @@
|
|||
"name": "azuracast",
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"dev": "npm ci && bash",
|
||||
"dev-build": "npm ci && npm run build",
|
||||
"build": "gulp",
|
||||
"generate-locales": "gettext-extract --attribute v-translate --keywords '$gettext' --output ../resources/locale/frontend.pot $(find ./vue -type f -name '*.vue' -o -name '*.js')",
|
||||
"import-locales": "gettext-compile --output ../resources/locale/translations.json $(find ../resources/locale/*.UTF-8 -type f -name '*.po')",
|
||||
"ci": "npm run import-locales && npm run build"
|
||||
"dev": "npm ci && bash",
|
||||
"dev-build": "npm ci && npm run build",
|
||||
"build": "gulp",
|
||||
"ci": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.15.5",
|
||||
|
@ -32,7 +30,6 @@
|
|||
"css-loader": "^1.0",
|
||||
"del": "^3.0.0",
|
||||
"dirrty": "^1.0.0",
|
||||
"easygettext": "^2.17.0",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-babel": "^8.0.0",
|
||||
"gulp-clean-css": "^3.9.2",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -24,12 +24,21 @@ class GenerateCommand extends CommandAbstract
|
|||
$exportDir = $environment->getBaseDirectory() . '/resources/locale';
|
||||
|
||||
$dest_file = $exportDir . '/default.pot';
|
||||
$frontendFile = $exportDir . '/frontend.pot';
|
||||
|
||||
$translations = new Translations();
|
||||
|
||||
if (file_exists($frontendFile)) {
|
||||
$translations->addFromPoFile($frontendFile);
|
||||
// Find all JS/Vue file translations.
|
||||
$directory = new RecursiveDirectoryIterator($environment->getBaseDirectory() . '/frontend/vue');
|
||||
$iterator = new RecursiveIteratorIterator($directory);
|
||||
|
||||
$vueRegex = new RegexIterator($iterator, '/^.+\.(vue)$/i', RecursiveRegexIterator::GET_MATCH);
|
||||
foreach ($vueRegex as $pathMatch) {
|
||||
$translations->addFromVueJsFile($pathMatch[0]);
|
||||
}
|
||||
|
||||
$jsRegex = new RegexIterator($iterator, '/^.+\.(js)$/i', RecursiveRegexIterator::GET_MATCH);
|
||||
foreach ($jsRegex as $pathMatch) {
|
||||
$translations->addFromJsCodeFile($pathMatch[0]);
|
||||
}
|
||||
|
||||
// Find all PHP/PHTML files in the application's code.
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace App\Console\Command\Locale;
|
|||
use App\Console\Command\CommandAbstract;
|
||||
use App\Environment;
|
||||
use App\Locale;
|
||||
use Gettext\Translation;
|
||||
use Gettext\Translations;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
|
@ -21,19 +22,47 @@ class ImportCommand extends CommandAbstract
|
|||
$locales = Locale::SUPPORTED_LOCALES;
|
||||
$locale_base = $environment->getBaseDirectory() . '/resources/locale';
|
||||
|
||||
$jsTranslations = [];
|
||||
|
||||
foreach ($locales as $locale_key => $locale_name) {
|
||||
$locale_source = $locale_base . '/' . $locale_key . '/LC_MESSAGES/default.po';
|
||||
|
||||
if (file_exists($locale_source)) {
|
||||
if (is_file($locale_source)) {
|
||||
$translations = Translations::fromPoFile($locale_source);
|
||||
|
||||
// Temporary inclusion of frontend translations
|
||||
$frontendTranslations = $locale_base . '/' . $locale_key . '/LC_MESSAGES/frontend.po';
|
||||
if (is_file($frontendTranslations)) {
|
||||
$frontendTranslations = Translations::fromPoFile($frontendTranslations);
|
||||
$translations->mergeWith($frontendTranslations);
|
||||
}
|
||||
|
||||
$locale_dest = $locale_base . '/compiled/' . $locale_key . '.php';
|
||||
$translations->toPhpArrayFile($locale_dest);
|
||||
|
||||
$localeJsKey = str_replace('.UTF-8', '', $locale_key);
|
||||
|
||||
/** @var Translation $translation */
|
||||
foreach ($translations as $translation) {
|
||||
if ($translation->isDisabled() || !$translation->hasTranslation()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$jsTranslations[$localeJsKey][$translation->getOriginal()] = $translation->getTranslation();
|
||||
}
|
||||
|
||||
$io->writeln(__('Imported locale: %s', $locale_key . ' (' . $locale_name . ')'));
|
||||
}
|
||||
}
|
||||
|
||||
$jsTranslations = json_encode(
|
||||
$jsTranslations,
|
||||
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
$jsTranslationsPath = $locale_base . '/translations.json';
|
||||
|
||||
file_put_contents($jsTranslationsPath, $jsTranslations);
|
||||
|
||||
$io->success('Locales imported.');
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue