使用多语言应用工具包时,我们的resx
和xlf
文件包含许多我们不想翻译的垃圾(例如控件的大小和位置)。
总有没有自动排除所有额外信息的信息?
如果没有,是使用多语言编辑器手动浏览XLIFF文件并将translatable
更改为False的唯一方法吗?
当资源文件包含图像时,问题甚至更加严重...
答案 0 :(得分:0)
在这里问了几天后,我尝试在official support page的Multilingual App Toolkit上问同样的问题,但我也没有得到答复。
因此,作为解决该问题的方法,我编写了python脚本来设置XLIFF文件中除am4core.useTheme(am4themes_animated);
var chart = am4core.create("chartdiv", am4charts.XYChart);
for (i = 0; i < data.length ; i++) {
chart.data.push({ "EmployeeName": data[i].EmployeeName, "Salary": data[i].Salary});
}
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "EmployeeName";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 30;
categoryAxis.renderer.labels.template.adapter.add("dy", function (dy, target) {
if (target.dataItem && target.dataItem.index & 2 == 2) {
return dy + 25;
}
return dy;
});
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = "Salary";
series.dataFields.categoryX = "EmployeeName";
//series.name = "Visits";
series.columns.template.tooltipText = "{categoryX}: [bold]{valueY}[/]";
series.columns.template.fillOpacity = .8;
var columnTemplate = series.columns.template;
columnTemplate.strokeWidth = 1;
columnTemplate.strokeOpacity = 1;
以外的所有其他属性,以便将它们标记为.Text
。多语言编辑器没有将“可翻译的”设置为批量操作的选项,而手动执行此操作将花费很多时间。
translate="No"
在Visual Studio中,我还必须手动打开每个表单并将#!/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()
属性设置为Localizable
,以便将True
的值保存在相应的.Text
中多语言应用工具包可以对其进行处理。