【问题标题】:translate only from /app/Resources/views with JmsI18NBundle仅使用 JmsI18NBundle 从 /app/Resources/views 翻译
【发布时间】:2016-06-13 00:21:00
【问题描述】:

我正在尝试从 /app/Resources/views 中分配的模板生成带有 jms_i18n_routing 的翻译文件 .xliff。如果可能的话,我只想拿一根名为“frontend.html.twig”的树枝

我正在使用下一个命令,但它仅从特定包生成翻译,但不翻译任何位于包目录之外的模板,例如,文件“app/Resources/views/frontend.html.twig”未翻译:

php app/console translation:extract en --enable-extractor=jms_i18n_routing --bundle="AcmeFooBundle"

谢谢!

【问题讨论】:

    标签: symfony internationalization


    【解决方案1】:

    我建议翻译文本使用 JMSTranslationBundle。仅使用 JmsI18NBundle 来转换路由。

    从特定目录“app/”生成翻译文件:

    $ php app/console translation:extract en_US --config=app --output-format=xliff --dir=app
    

    从特定文件名生成翻译文件:

    1. 向 jms_translation 添加配置
    # file: app/config/config.yml
    jms_translation:
        source_language: "%locale%"
        configs:
            app:
                dirs: [%kernel.root_dir%, %kernel.root_dir%/../src]
                output_dir: %kernel.root_dir%/Resources/translations
                ignored_domains: [routes]
                excluded_names: ["*TestCase.php", "*Test.php", "*.php"]
                excluded_dirs: [cache, data, logs]
            custom_exclude_from_app:
                dirs: [%kernel.root_dir%]
                output_dir: %kernel.root_dir%/Resources/translations
                ignored_domains: [routes]
                excluded_names: ["*TestCase.php", "*Test.php", "*.php", "backend.html.twig", "email_template.html.twig", "another_template_excluded.html.twig"]
                excluded_dirs: [cache, data, logs]
    
    1. 执行以下命令:

    $ php app/console translation:extract en_US --config=custom_exclude_from_app --output-format=xliff --dir=app
    

    【讨论】:

    • 你能添加一个路由翻译的例子吗?要了解我如何自己翻译,因为该捆绑包无法与 Symfony4 一起使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-04
    • 2019-11-07
    相关资源
    最近更新 更多