技术求助:如何入门i18n-ally?翻译自制VSCode扩展失效且无get started指引
Hey there, let's tackle your issues step by step—whether it's getting started with i18n-ally or fixing those unresponsive translation actions for your VS Code extension.
1. Quick Start with i18n-ally
Since you couldn't find the get started guide, here's a condensed, practical walkthrough to get you going:
- Install the extension: Search for
i18n-allyin VS Code's Extensions panel and hit install. - Set up your config: Create a
.vscode/i18n-ally-custom.json(or edit workspace settings) to define your translation structure. At minimum, add these core settings:{ "localesPaths": ["src/locales"], "primaryLocale": "en", "fallbackLocale": "en", "enabledParsers": ["json", "ts", "py"] } - Initialize translation files: Create a folder (like
src/locales) with your primary locale file (e.g.,en.json) and add initial key-value pairs:{ "greeting": "Hello World", "extension.name": "My Custom Extension" } - Start translating: Right-click on a string in your code, select
i18n-ally: Extract to locale key, and follow prompts to add it to your locale files.
2. Fixing "No Actions Take Effect" Issue
If none of your translation operations work, try these troubleshooting steps:
- Verify config correctness: Double-check that
enabledParsersincludesjson,ts, andpyin your i18n-ally settings. Also confirmlocalesPathspoints to the actual folder where your translation files live. - Check file associations: Make sure VS Code recognizes your files correctly (e.g.,
.tsfiles are marked as TypeScript,.pyas Python). Incorrect file types can prevent i18n-ally from parsing them. - Validate translation syntax: Ensure your locale files have valid syntax (no missing commas in JSON, no typos in TypeScript/Python dictionaries). A single syntax error can break the entire setup.
- Restart VS Code and extension: Sometimes a fresh start fixes glitches—try reloading the window (
Ctrl+Shift+P→Reload Window) or disabling/enabling i18n-ally again.
3. Handling Different File Types
Here's how to work with your specific file types:
- JSON: i18n-ally natively supports JSON locale files. For your extension's
package.json, use%extension.name%to reference translation keys—i18n-ally will pick them up if your config is set correctly. - TypeScript: Use a translation function (like
t('greeting')) in your code. Configure thetranslationFunctionsetting to let i18n-ally detect these calls:
Make sure your TypeScript code imports the translation function from your i18n setup (e.g., using"translationFunction": ["t", "$t", "i18n.t"]vscode-nlsfor VS Code extensions). - Python: If your extension has Python components, use gettext or libraries like
python-i18n. i18n-ally can parse.po/.mofiles or Python dictionaries—just addpoorpytoenabledParsersand pointlocalesPathsto your Python translation directory.
内容的提问来源于stack exchange,提问作者Frank4466
相关产品推荐
相关产品推荐

