The Deska blog
Extracting Hardcoded Strings for i18n With an Agent
Learn how to optimize extracting hardcoded strings for i18n using AI agents to automate the internationalization of your codebase efficiently.
· 12 min read
Internationalizing a mature codebase often starts with the tedious task of extracting hardcoded strings for i18n. This process involves identifying user facing text within source files, replacing those literals with translation keys, and populating a resource file. While manual extraction ensures high precision, it is notoriously slow and prone to human error, especially in large projects. By leveraging an AI agent, developers can automate the discovery and replacement phases, significantly reducing the time required to prepare a software project for global markets.
The Challenges of Manual i18n Extraction
Manually searching for strings is a labor intensive process that distracts developers from building features. The complexity increases when dealing with dynamic content, such as template literals or variables concatenated with text.
- High risk of missing strings in deeply nested components.
- Inconsistent key naming conventions when multiple developers handle extraction.
- Difficulty distinguishing between user facing strings and internal keys, constants, or logging messages.
- The repetitive nature of the task leads to fatigue and oversight.
Traditional grep based approaches or regex scripts offer some relief. However, they lack the contextual awareness needed to determine if a string actually requires translation. An AI agent provides the semantic understanding necessary to make these distinctions accurately.
How AI Agents Transform the Workflow
Modern coding agents can parse the abstract syntax tree of your code to identify candidate strings. Unlike simple search tools, an agent understands the difference between a console.log argument and a button label. When you use an agent for extracting hardcoded strings for i18n, you transition from a manual editor to a reviewer.
The agent can suggest logical keys based on the context of the component. For instance, a string like "Submit Form" inside a ContactUs component might be automatically keyed as contact_us.buttons.submit. This semantic naming helps maintain a clean and organized localization file.
Implementing Extraction with Deska
Deska provides an environment where you can run multiple AI agents side by side to handle large scale refactoring tasks. By using the infinite canvas, you can place your code editor next to several agent terminals to monitor the extraction process in real time.
If you are using agents like Claude Code or Codex CLI within Deska, you can prompt them to scan specific directories. Because Deska is a local-first application, your source code remains on your machine while the agent processes the files. You can use the coding agents to perform the following steps:
- Identify all JSX or HTML files containing untranslated text.
- Replace the text with a translation function call, such as
t('key_name'). - Append the new key and the original value to a central
en.jsonormessages.pofile.
The advantage of using Deska is the ability to see the impact of these changes instantly. You can open a browser widget to see the application UI and a terminal to run your test suite. If the agent makes a mistake, the Ask Deska assistant can help you revert changes or refine the agent instructions through simple voice commands.
Comparison of Extraction Methods
Moving toward an agent based workflow requires understanding how it sits alongside veteran tools.
| Method | Accuracy | Speed | Context Awareness |
|---|---|---|---|
| Manual | Very High | Very Low | Human Intelligence |
| Regex Scripts | Low | High | None |
| Static Analysis | Medium | High | Functional |
| AI Agents | High | High | Semantic |
Tools like i18next-parser or formatjs are excellent for static analysis. They reliably find tagged strings but often struggle with the initial move from hardcoded text to tags. This is where agents excel. They fill the gap between "plain text" and "ready for localization." These tools differ in approach, where static analysis is deterministic and agents are probabilistic. Combining them usually yields the best results.
Best Practices for Agent Based i18n
When you task an agent with extracting hardcoded strings for i18n, specific instructions will improve the quality of the output.
- Define a clear naming convention for keys before starting the process.
- Instruct the agent to ignore specific files, such as test suites or configuration files.
- Use a "dry run" mode where the agent lists the proposed changes before applying them to the filesystem.
- Review the generated resource files for duplicates or overly generic keys like
label1ortext2. - Ensure the agent handles pluralization and interpolation correctly, as these are common points of failure.
By running these agents in panels within a Deska workspace, you can manage the complexity of a multi-module project. You can even monitor the progress of a long running extraction task from your phone using the mobile app, which connects via a secure relay without exposing ports.
Automated Verification Post Extraction
After the agent completes the extraction, the next critical step is verification. You should run a linter or a specialized i18n tool to ensure all keys exist in your translation files. Automated tests should verify that the UI still renders correctly and that no logic was broken during the string replacement.
In Deska, you can keep a tab open for your notes to document any edge cases the agent encountered. This documentation is vital for other team members who will maintain the localization files in the future.
FAQ
How to automate extracting hardcoded strings for i18n?
You can automate this by using AI coding agents that support filesystem access. Provide the agent with a prompt specifying the translation library you use and the desired key format. The agent will then iterate through your files, replace literals with function calls, and update your JSON translation bundles.
Can AI agents handle complex string interpolation?
Yes, modern agents can identify variables within strings and convert them into the specific syntax required by libraries like react-i18next or vue-i18n. However, it is important to review these specific instances to ensure the variable names in the translation file match the logic in the code.
Is it safe to use AI for internationalization?
Using AI for internationalization is safe if you use a local-first environment and review the diffs before committing. Agents can occasionally misidentify strings, such as internal IDs, so a human in the loop remains necessary for quality assurance.
Start Your Internationalization Journey
Internationalizing your application does not have to be a month-long manual project. By integrating AI agents into your development environment, you can handle the heavy lifting of string extraction with a few precise commands.
Download Deska today to explore how the infinite canvas and side by side agent panels can accelerate your localization workflow. Using your own API keys via the pricing model ensures you have full control over the AI models driving your productivity.