如何导出与导入字符串资源文件?表单标签批量处理咨询
1. Simple Export/Import of ResX Files
Absolutely—there are straightforward tools to handle this without complex setup:
Visual Studio Built-In Workflow:
Open your.resxfile in Visual Studio’s Resource Editor. Right-click inside the editor or go to the "Tools" menu, then select "Export..." to save the content as a CSV or XML file. CSV is the best pick for translators since it’s a simple table with columns forName(resource key),Value(text to translate), andComment(context notes for clarity). Once translated, use the "Import..." option in the same editor to load the updated CSV back into the resx file. Just remind your translators not to modify theNamecolumn—those keys are what link the translated text back to your code..NET CLI Commands:
If you prefer command-line work, install thedotnet-resxtool first with:dotnet tool install -g dotnet-resxThen export a resx file to CSV:
dotnet resx export -i strings.resx -o strings-to-translate.csvAfter translation, import the updated CSV into a new localized resx file (e.g., for French):
dotnet resx import -i strings-translated-fr.csv -o strings.fr-FR.resxThis supports CSV, JSON, and XML formats, so you can pick what your translators prefer.
2. Batch Exporting Multiple Form ResX Files into a Single File
You absolutely can batch these into one file and map them back correctly later—here’s how:
ResXManager Extension (Visual Studio):
This free extension is made for exactly this scenario. Install it, then right-click your project and select "ResXManager". It will scan all resx files in your project; you can select all your form-related resx files (e.g.,Form1.resx,Form2.ar-EG.resx, etc.) and export them into a single CSV. The exported file will include an extraFileNamecolumn that tracks which original resx each string belongs to. When you import the translated file back, the extension automatically splits the content into the correct resx files—no manual work needed.Custom Script (PowerShell/C#):
If you want full control, write a quick script to aggregate the files. For example, a PowerShell script can:- Loop through all your form resx files.
- Load each as an XML document and extract
<data>elements. - Append rows to a CSV with columns:
FileName,Name,Value,Comment.
After translation, reverse the process: read the CSV, group entries byFileName, and write the translated values back into the corresponding resx files.
Quick Tips to Avoid Headaches
- Lock the
NameandFileNamecolumns for translators—these are non-negotiable for correct mapping. - Use UTF-8 encoding for exported files to handle accented characters in French and Italian (é, è, ù, ò, etc.).
- Create empty
strings.fr-FR.resxandstrings.it-IT.resxfiles before importing translations—this ensures your project recognizes them as valid localized resources. - After importing, open the resx files in Visual Studio to check for syntax errors (the editor will flag any issues immediately).
内容的提问来源于stack exchange,提问作者Bassem Kamal M

