When using the Multilingual App Toolkit, our resx
and xlf
files contain lots of junk that we don't want translating (like a control's size and location).
Is there anyway to automatically exclude all the extra information?
If not, is the only way to manually go through the XLIFF file using the Multilingual Editor and change translatable
to False?
The problem is even worse when the resource file contains images...
A few days after asking here, I tried asking the same question at the official support page for Multilingual App Toolkit, but I didn't get a reply there either.
So, as a workaround to the problem I've written a python script to set all of the properties other than .Text
in the XLIFF files so that they are marked as translate="No"
. The Multilingual Editor doesn't have an option to set "Translatable" as a bulk operation, and doing this manually would take forever.
#!/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()
In Visual Studio, I also had to manually open every form and set the Localizable
property to True
so that the .Text
values are saved in the corresponding .resx
where the Multilingual App Toolkit can process them.
In my case I wanted to ignore on a per-file basis, so this was helpful for me: https://multilingualapptoolkit.uservoice.com/forums/231158-general/suggestions/13627704-add-ignore-exclude-filter-for-resx-files
I basically added
<SuppressAutomaticLocalization>true</SuppressAutomaticLocalization>
in the EmbeddedResource tag in the .csproj file, resulting in:
<ItemGroup>
<EmbeddedResource Update="Properties\Authorization\Components_Actions.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Components_Actions.Designer.cs</LastGenOutput>
<SuppressAutomaticLocalization>true</SuppressAutomaticLocalization>
</EmbeddedResource>
...
More Info: If the .resx File is not listed in your .csproj file, make sure to set the AccessModifier in the .resx file editor. If no selection is made, the file does not appear in the .csproj
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.