All Collections
For Developers
Developer Hub
How String Hashes Are Calculated
How String Hashes Are Calculated

Learn how string hashes are created in Transifex.

T
Written by Transifex
Updated over a week ago

There is a Transifex-specific way to identify a translation string. You can calculate the md5 hash of the concatenation of the key and the context and take the hexadecimal digest of the result. If no context is defined, you should use an empty string as it.

So, in Python, the string hash would be calculated by the following program:

from hashlib import md5 if isinstance(context, list): if context: keys = [string_key] + context else: keys = [string_key, ''] else: if context == 'None': keys = [string_key, ''] else: keys = [string_key, context] return md5(':'.join(keys).encode('utf-8')).hexdigest()

Or, in JavaScript:

// Array with source string content and context. // If the context doesn't exist, it should be empty. var content = ["Source string", ""]; var string_hash = md5(content.join(':'));


Finding the hexdigest of Transifex Live strings

If you create a hexdigest of Transifex Live strings, the digest must be created from the key.

from hashlib import md5 key = md5(source_string.encode('utf-8')).hexdigest() return ':'.join([key,''])


String Hash Exceptions

  1. JSON and RequireJS require an additional step to ensure we can accurately match a hash. You must first escape all . and \ characters. In addition, special care must be taken when using any form of nesting (lists and other documents). An example Python program and detailed explanation are in the respective JSON format sections.

  2. In the case of PO (version=2), the colon character (:) must be escaped with a single backslash ( \ ).

  3. When non-UTF-8 characters are included in a source string, you need to decode the string first as follows:

    keys = ["key_of_the_string".decode('utf-8'), '']


💡Tip

Looking for more help? Get support from our Transifex Community Forum!

Find answers or post to get help from Transifex Support and our Community.

Did this answer your question?