I am interested to know is there a script or otherway available to collect and generate Yii translation messages in a controller/project
Eg. If I have the following code
That sounds like a job for grep
and a regular expression. Search for this:
Yii::t\s*\(\s*('(?:[^']|(?<=\\)')*'|"(?:[^"]|(?<=\\)")*")\s*,\s*('(?:[^']|(?<=\\)')*'|"(?:[^"]|(?<=\\)")*")\s*\)
Since the above is unfortunately unreadable, I 'll break it down a bit:
Yii::t\s*\(\s*##PATTERN##\s*,\s*##PATTERN##\s*\)
This obviously matches a call to Yii::t
taking care to account for whitespace. The secret sauce is ##PATTERN##
, which is repeated twice. ##PATTERN##
is
('(?:[^']|(?<=\\)')*'|"(?:[^"]|(?<=\\)")*")
The above matches either '([^']|(?<=\\)')*'
(a singly quoted string) or "([^"]|(?<=\\)")*"
(a doubly quoted string). Non-capturing groups (?:
) have been used to disregard interim results that are of no interest.
After matching with this regex, capturing group #1 will hold the translation file name (e.g. 'blog'
) and group #2 will hold the string name (e.g. 'Your name'
).