"Pain is pain, whatever you call it.
This is fear, where there is fear, there is no place for love."
Agatha Christie
How many projects have not passed through my hands - always the same - the translation files are in a terrible state. This problem is best expressed by the words of Agatha Christie at the beginning of the article. The linguistic nuances and quality of translations will not be understood here. Suppose we have excellent translations. Under the cut, those problems that can be controlled by technical means and the tools designed for this are sorted out. The material is intended for people with experience with Symfony and in general with the Linux console. It is also assumed that you know how to connect third-party bundles to the project. Therefore, some of the questions are not dealt with from the standpoint of βeverything is clear as it isβ.
Of all the problems associated with translations, there are those that are very difficult to control by technical means. For example, the quality of translations, their semantic meaning, and the appropriateness of using certain words in a particular part of the user interface. And there are those that are technically quite easy to control. From the last category, which we usually encounter on projects, we can single out:
Lack of some translations. Even if translations for one or two languages ββare added, they are not added for the rest.
No translations added at all.
Using similar but nevertheless different prickles for the same translations.
Different translations for the same keys (duplicate keys). As a result, we get that the required translation is available, but not what we expect is displayed.
But this is an outward manifestation of the problem. What is its basis?
3 :
. ? . . . . .
: . , , . . .
? . . PHPUnit. , CI ? - , .
. , 100500 . , βsymfony/translationβ. , , . , , .
. , . Github-. Symfony 4.4+ . .
, , β ββ . , YAML . . β . . , . :
. , , - , .
.
. ( ) . , .
:
aeliot_trans_maintain:yaml:transform PATH_TO_FILE_IN PATH_TO_FILE_OUT
Symfony. , PATH_TO_FILE_OUT PATH_TO_FILE_IN. . Linux find grep . , YAML :
find PATH_TO_DIRECTORY -type f \( -iname \*.yml -o -iname \*.yaml \) | sort | xargs -I {} -t php bin/console aeliot_trans_maintain:yaml:transform $1{}
,
. β , Google Translate. , . . .
:
bin/console aeliot_trans_maintain:yaml:export_missed_translations DOMAIN DONOR_LOCALE FILTER_BY_LOCALE
:
DOMAIN β .
DONOR_LOCALE β
FILTER_BY_LOCALE β . , , . , .
. StdOut. . :
bin/console a:y:e messages en de > ./donor.txt
- , Symfony . .
PhpStorm . . , , .
! . YAML Symfony (\Symfony\Component\Yaml\Yaml::dump()), . , . .
, β . ( : insert_missed_keys). , , , .
:
no β . .
end β
merge β . .
: no end. dev , .. . - , - .
:
parameters:
env(TRANS_MAINTAIN_INSERT_MISSED_KEYS): no
aeliot_trans_maintain:
insert_missed_keys: "%env(TRANS_MAINTAIN_INSERT_MISSED_KEYS)%"
/ TRANS_MAINTAIN_INSERT_MISSED_KEYS .env .env.local - .
. . . . β¦ . ? ?
:
aeliot_trans_maintain:lint:yaml KEY_1 KEY_2 KEY_N
0 1 . StdOut . . .
:
base β ().
all β . . , base , all .
:
files_missed β , . , . , .
keys_missed β , . , ( ) , . , , .
keys_duplicated β . , , .
base. , .
CI . , - , .
.
:
. , .
.
API Google/Yandex . .
. .