What is a translation key? A guide with examples
When navigating SimpleLocalize's documentation, pricing page, or the software itself, you'll frequently come across the term 'translation key.' In this blog post, we'll explain what a translation key is, how to create them, and how to manage translation keys in your project. Let's dive in!
What is a translation key?
A translation key is a unique identifier for translations within your project files. Each translation key corresponds to a single text element in your app or website. The content within a translation key can range from a single word to longer text blocks. Using translation keys simplifies the process of creating and managing translations in software development.
A single translation key can be translated into multiple languages, allowing the text inside that key to vary depending on the selected language.
Translation key for developers
Developers can easily identify or create translation keys, as they originate from the source code of the website or application.
The formatting of translation keys varies based on the library used and the internal guidelines for managing them. Here are some examples:
TRANSLATION_KEY
TRANSLATION.KEY
tranlsationKey
tranlsation_key
If your project supports only one language, and you add texts directly into the code of your website or app, the translation key refers to the entire text element. For example, the header or paragraph below:
When using multiple languages, in the translation files in your project, you will find the translation key as a source to identify the translation. For example, below you can see translation keys with translations in English in a JSON file:
Translation keys in SimpleLocalize
At SimpleLocalize, we love to make things easier. Instead of calculating words or characters to determine your project volume or scope, we count the number of translation keys.
As illustrated below, it's quite straightforward. In the translation editor, all translations assigned to specific translation keys are visible. While they may consist of multiple languages and various lengths, the translation key remains unique.
Thanks to that, regardless of the length of your translations or the number of languages you use, the quantity of translation keys remains the same. Naturally, this changes if you create additional translation keys, such as when incorporating new features and texts that necessitate translations.
To determine the SimpleLocalize plan suitable for your project, simply check how many translation keys your project currently holds. Opt for the best-fitting plan, and as you add more translation keys, simply add a pack of extra keys to expand your current plan. Check out our pricing page for more details.
How to create translation keys?
For optimal clarity and simplicity in translation management, there are some general rules for creating translation keys. While not mandatory, they significantly enhance the ease of use for both developers and translators.
General rules for creating translation keys:
- Descriptive and contextual. Translation keys should be self-explanatory and describe the content clearly. For example,
GUEST_DETAILS.BIRTHDATE_LABEL
. By looking at it, you should know what translation is inside. - Consistent. Maintain consistency in naming conventions and structure of your translation keys. For example,
button.next
,button.cancel
. Keeping the same structure will make it easier to find translation keys and edit translations. - Readable. They should be easy to read and comprehensive for everyone. Use dots, camel case, or underscore to make it easier to visually read the translation key.
- Scalable. Design keys to accommodate future additions and modifications to the content. Instead of mirroring the original text 1:1, craft unique yet descriptive keys. For example, instead of
welcome.search.enter-your-name-or-booking-id-here
, create a simple keywelcome.search.label
.
Additionally, there are also some other rules applied directly by the translation libraries. For instance, i18next can additionally use namespaces added to translation keys, and translation keys elements must be separated by dots.
Our recommendations for creating translation keys
Besides the general rules, we wanted to share with you some of our 'dos and don'ts' about creating translation keys that can be helpful for getting started:
- Don't use spaces. They will make the key harder to read and can be confused with translations.
- Don't use special characters.
- Create actual translation keys instead of just using existing text from the original language.
- Don't use abbreviations - they may be clear for you but not for the translator or another developer.
- For buttons or elements that repeat in multiple places, use one general translation key instead of multiple ones that duplicate them.
- Don't use unreadable keys, like
s0xD2_#
. - Avoid creating too long keys - remember that they must be easy to read.
Whether opting for lowercase, uppercase, dots, or underscores, keep in mind the general rules and our tips for creating translation keys for effective translation management and simpler workflows for your team.
Read more about best practices for translation keys.
For more about translation management, visit our other blog posts or contact us if you have any questions!