feat: Find lang() strings and update localization keys |
How would you like to add the lang:find command? It will scan all the files of the app/ project (except Languages), find all applications of lang() and update non-existent keys.
The algorithm is something like this:
* We scan the system for .php files. * We read the files and use regular expressions to find lang() inserts. * The found array with "Filename.translate" is run in a loop. * We match the first element with the translation file, the remaining elements are keys for translation. If the language file exists, compare the keys, otherwise we will create a new file. * Compare translations and update/add keys. * Since there is no actual localizatiin, we fill it in as a key. 'title' => '# title #' I'm sorry, I'm writing from my phone. I will add to the topic over time, if it's interesting.
See https://github.com/clsmedia/ci4-translation-finder
I think the implementation of this package can be used as a reference.
No, i create new variant. He add multi array from Test.alert.succes.title (to [ ... ]).
I didn't see it saving to the right file. Only table with strings. Regex for search, ok, i like...
@kenjis Tell me how best to do tests when scanning the APPPATH? I will need to check the creation of files and add fakes to app/Controllers. And delete them after the tests.
Do I still need to add php-cs-fixer after execution? The array dump has incorrect formatting. (08-21-2023, 10:59 PM)ozornick Wrote: I will need to check the creation of files and add fakes to app/Controllers. And delete them after the tests. If you need that, do it. Add fakes to app/Controllers. And delete them after the tests. But it may be better to use Tests\Support namespace. It is the namespace for testing. You do not need to delete after the tests. See https://github.com/codeigniter4/CodeIgni...s/_support (08-21-2023, 10:59 PM)ozornick Wrote: Do I still need to add php-cs-fixer after execution? The array dump has incorrect formatting. Yes. Run `composer cs-fix` always. @kenjis see pls fork https://github.com/neznaika0/codeigniter...age-finder
* The command lang :find searches for translation (lines lang('File.key')) files in the default APPPATH folder and ignoring APPPATH . Language/ path. * The command is able to recognize nested keys normally (File.form.placeholder.text). After the update, the developer only needs to add the necessary translation, and not search through the entire lang() code * Bad lines are skipped. * Added some tests. After checking, the created files are cleared. I need a response for a reliable PR. Known issues: ! Each update overwrites comments in the language file
! php-cs-fixer may not work for appstarter project (if require-dev disabled)
! I would like to add translations where they possibly should be, for example, Config/Validation ! It would be nice to add hints (boolean) if the translation contains variables. For example, File.form.placeholder.text {vars} will indicate the presence of some dependencies in the phrase
1. Update all in APPPATH and default locale: Code: $ php spark lang:find 2. Find and update translations in a specific folder (+ subfolders) and select a new locale: Code: $ php spark lang:find --dir Controllers/Translation --locale ru 3. Find translations and show table with new translations: Code: $ php spark lang:find --dir Controllers/Translation --show-new 4. Detailed output. Can be added to other options: Code: $ php spark lang:find --verbose --dir Controllers/Translation --show-new Code: aleksandr@aleksandr-debian:~/www/ci-demo$ php spark lang:find --dir Controllers/Translation --verbose --show-new PHP Code: // Language/{locale}/TranslationThree.php
The PR is in progress.
See https://github.com/codeigniter4/CodeIgniter4/pull/7896
I would like to show you the improved command lang:finder. This is practically the same function lang:find with improvements. It would be good to get feedback if someone uses it.
PHP Code: composer require neznaika0/codeigniter-lang-finder |
Welcome Guest, Not a member yet? Register Sign In |