How to generate translation file (.po, .xliff, .yml,…) from a Symfony2/Silex project?

前端 未结 3 1508
野性不改
野性不改 2021-02-09 15:56

Im going to build a Silex/Symfony2 project and I have been looking around for a method to generate XLIFF/PO/YAML translation files based on texts-to-be-translated inside the pro

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 16:39

    Workaround for busy people (UNIX)

    You can run the following command in the Terminal:

    $ grep -rEo --no-filename "'.+'\|\btrans\b" templates/ > output.txt
    

    This will output the list of messages to translate:

    'Please provide your email'|trans
    'Phone'|trans
    'Please provide your phone number'|trans
    ...
    

    I mean almost.. But you can usually do some work from here...

    Obviously you must tweak the command to your liking (transchoice, double-quotes instead of single...).

    Not ideal but can help!

    grep options

    • grep -R, -r, --recursive: Read all files under each directory, recursively this is equivalent to the -d recurse option.
    • grep -E, --extended-regexp: Interpret PATTERN as an extended regular expression.
    • grep -o, --only-matching: Show only the part of a matching line that matches PATTERN.
    • grep -h, --no-filename: Suppress the prefixing of filenames on output when multiple files are searched.

    (source)

提交回复
热议问题