【问题标题】:Automatically exclude strings - Multilingual App Toolkit自动排除字符串 - 多语言应用工具包
【发布时间】:2019-02-14 13:27:55
【问题描述】:

在使用多语言应用工具包时,我们的 resxxlf 文件包含许多我们不想翻译的垃圾(例如控件的大小和位置)。

是否有自动排除所有额外信息?

如果不是,是否只有使用多语言编辑器手动浏览 XLIFF 文件并将translatable 更改为 False 的方法?

当资源文件包含图片时,问题就更严重了……

【问题讨论】:

    标签: c# multilingual-app-toolkit


    【解决方案1】:

    在这里提问几天后,我尝试在 official support page 上针对 Multilingual App Toolkit 提出同样的问题,但我也没有得到回复。

    因此,作为该问题的解决方法,我编写了一个 python 脚本来设置 XLIFF 文件中除.Text 之外的所有属性,以便将它们标记为translate="No"。多语言编辑器没有将“可翻译”设置为批量操作的选项,手动执行此操作将需要很长时间。

    #!/usr/bin/env python
    from lxml import etree
    import os
    
    
    NEW_LINE = '\r\n'
    
    
    def set_translatable(filepath):
        """
        Each string in the XLF file is set to translatable False unless
        it is the `.Text` attribute that we actually want translated.
    
        """
        doc = etree.parse(filepath)
    
        for d in doc.iter():
            if 'trans-unit' in d.tag:
                translate = False
                for k, v in d.items():
                    if k == 'id':
                        if v.endswith('.Text'):
                            translate = True
                translate = 'yes' if translate else 'no'
                d.set('translate', translate)
        with open(filepath, 'w') as out_file:
            doc.write(out_file)
    
    
    def main():
        cwd = os.getcwd()
    
        for subdir, dirs, files in os.walk(cwd):
            for file in files:
                if filepath.endswith('.xlf'):
                    set_translatable(filepath)          
    
    
    if __name__ == '__main__':
        main()
    
    

    在 Visual Studio 中,我还必须手动打开每个表单并将 Localizable 属性设置为 True,以便将 .Text 值保存在相应的 .resx 中,多语言应用工具包可以处理它们。

    【讨论】:

    • 我可能是错的,但工具包不是基于 XML 的吗?微软正在终止对他们的翻译服务的 XML 支持,我未经研究的理解是,这最终会破坏多语言应用程序工具包......如果你知道更多,请分享。
    • 我假设(希望)MAT 团队已经意识到这一点,并将发布一个更新,让 MS 翻译服务仍然可以使用。翻译服务迁移到 Azure 时有更新。
    • 几天前我在 Twitter 上与作者通信。我试图使用自定义翻译。由于 MAT 只与 2.0 版本的 API 对话,它不能使用自定义翻译。他提到他会看到加快实现 v3.0 API 调用的时间表,但没有具体说明。
    【解决方案2】:

    在我的情况下,我想忽略每个文件,所以这对我很有帮助:https://multilingualapptoolkit.uservoice.com/forums/231158-general/suggestions/13627704-add-ignore-exclude-filter-for-resx-files

    我基本上加了

    <SuppressAutomaticLocalization>true</SuppressAutomaticLocalization>
    

    在.csproj文件的EmbeddedResource标签中,导致:

    <ItemGroup>
      <EmbeddedResource Update="Properties\Authorization\Components_Actions.resx">
        <Generator>ResXFileCodeGenerator</Generator>
        <LastGenOutput>Components_Actions.Designer.cs</LastGenOutput>
        <SuppressAutomaticLocalization>true</SuppressAutomaticLocalization>
      </EmbeddedResource>
    ...
    

    更多信息: 如果 .resx 文件未在 .csproj 文件中列出,请确保在 .resx 文件编辑器中设置 AccessModifier。如果未进行选择,则该文件不会出现在 .csproj 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      相关资源
      最近更新 更多