Good evening, there is a task to translate a file using gettext, PHP
It is necessary to translate some words that are in the array of the .txt file in parentheses, for example:
... [BP:UB:body:bodies]... -> ... [BP:UB:body:bodies]...
save translated words to a file with also a name in an arbitrary directory, example:
was a project/body_default.txt file :
======
...
[BODY:BASIC_1PARTBODY]
Categories are user-defined strings that can be used elsewhere to refer to groups of bodyparts for other commands.
[BP:UB:body:bodies] [UPPERBODY] [LOWERBODY] [CATEGORY:BODY]
This command establishes the relative size of body parts within a creature. The numbers have no absolute meaning or units.
[DEFAULT_RELSIZE:2000]
...
now the project/tr/body_default.txt file:
=======
...
[BODY:BASIC_1PARTBODY]
Categories are user-defined strings that can be used elsewhere to refer to groups of bodyparts for other commands.
[BP:UB:body:body] [UPPERBODY] [LOWERBODY] [CATEGORY:BODY]
This command establishes the relative size of body parts within a creature. The numbers have no absolute meaning or units.
[DEFAULT_RELSIZE:2000]
...
------------
there are source files in English: body_default.txt, plant_crops.txt
there is a translation ru_RU_tr.po, ru_RU_tr.mo with the exact positioning of the symbols for translation, example:
...
#: body_default.txt:7 //file name: line number for translation
msgctxt "BODY:BASIC_1PARTBODY" // context if there are two identical translations in the array
msgid "[BP:UB:body:bodies]" // what to scan in English
msgstr "[BP:UB:body:body]" // what needs to be replaced with Russian
...
wrote a simple translation script with output on the screen (while on the screen, if it works, then I wanted to cut the entry into the file), the problem is that for example, the word hello is translated into hello, but if the word is in an array and surrounded by characters, it no longer works. Knowledge is not enough to write a scanner and replace in an array, if such a thing is of course possible. Maybe there is a ready-made solution, I just dont know?
25.12.2022 21:05