Welcome Guest, Not a member yet? Register   Sign In
feat: Find lang() strings and update localization keys
#7

(This post was last modified: 08-31-2023, 06:37 AM by ozornick.)

@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 
$ php spark lang:find --dir Controllers/Translation --show-new --locale ru


4. Detailed output. Can be added to other options:

Code:
$ php spark lang:find --verbose --dir Controllers/Translation --show-new
$ php spark lang:find --verbose --locale ru


Code:
aleksandr@aleksandr-debian:~/www/ci-demo$ php spark lang:find --dir Controllers/Translation --verbose --show-new

CodeIgniter v4.3.7 Command Line Tool - Server Time: 2023-08-31 16:15:26 UTC+03:00

Current locale: ru
Find phrases in /home/aleksandr/www/ci-demo/app/Controllers/Translation folder...
File found: Controllers/Translation/TranslationTwo.php
File found: Controllers/Translation/TranslationOne.php
File found: Controllers/Translation/TranslationThree.php
+------------------+----------------------------------------------------+
| File            | Key                                                |
+------------------+----------------------------------------------------+
| TranslationOne  | TranslationOne.Copyright                          |
| TranslationOne  | TranslationOne.DESCRIPTION                        |
| TranslationOne  | TranslationOne.last_operation_success              |
| TranslationOne  | TranslationOne.metaTags                            |
| TranslationOne  | TranslationOne.overflow_style                      |
| TranslationOne  | TranslationOne.subTitle                            |
| TranslationOne  | TranslationOne.title                              |
| TranslationThree | TranslationThree.alerts.CANCELED                  |
| TranslationThree | TranslationThree.alerts.DELETED                    |
| TranslationThree | TranslationThree.alerts.Updated                    |
| TranslationThree | TranslationThree.alerts.created                    |
| TranslationThree | TranslationThree.alerts.failed_insert              |
| TranslationThree | TranslationThree.alerts.missing_keys              |
| TranslationThree | TranslationThree.formErrors.edit.INVALID_TEXT      |
| TranslationThree | TranslationThree.formErrors.edit.empty_name        |
| TranslationThree | TranslationThree.formErrors.edit.missing_short_tag |
| TranslationThree | TranslationThree.formFields.edit.TEXT              |
| TranslationThree | TranslationThree.formFields.edit.name              |
| TranslationThree | TranslationThree.formFields.edit.short_tag        |
| TranslationThree | TranslationThree.formFields.new.TEXT              |
| TranslationThree | TranslationThree.formFields.new.name              |
| TranslationThree | TranslationThree.formFields.new.short_tag          |
+------------------+----------------------------------------------------+

Files found: 3
New translates found: 22
All operations done!

PHP Code:
// Language/{locale}/TranslationThree.php
<?php

return [
    'alerts' => [
        'created'      => 'TranslationThree.alerts.created',
        'failed_insert' => 'TranslationThree.alerts.failed_insert',
        'CANCELED'      => 'TranslationThree.alerts.CANCELED',
        'missing_keys'  => 'TranslationThree.alerts.missing_keys',
        'Updated'      => 'TranslationThree.alerts.Updated',
        'DELETED'      => 'TranslationThree.alerts.DELETED',
    ],
    'formFields' => [
        'new' => [
            'name'      => 'TranslationThree.formFields.new.name',
            'TEXT'      => 'TranslationThree.formFields.new.TEXT',
            'short_tag' => 'TranslationThree.formFields.new.short_tag',
        ],
        'edit' => [
            'name'      => 'TranslationThree.formFields.edit.name',
            'TEXT'      => 'TranslationThree.formFields.edit.TEXT',
            'short_tag' => 'TranslationThree.formFields.edit.short_tag',
        ],
    ],
    'formErrors' => [
        'edit' => [
            'empty_name'        => 'TranslationThree.formErrors.edit.empty_name',
            'INVALID_TEXT'      => 'TranslationThree.formErrors.edit.INVALID_TEXT',
            'missing_short_tag' => 'TranslationThree.formErrors.edit.missing_short_tag',
        ],
    ],
]; 
Simple CI 4 project for beginners codeigniter-expenses
Reply


Messages In This Thread
RE: feat: Find lang() strings and update localization keys - by ozornick - 08-31-2023, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB