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. In case there's no context 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 context doesn't exists, it should be empty. var content = ["Source string", ""]; var string_hash = md5(content.join(':'));


Finding the hexdigest of Transifex Live strings

If you are creating 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. Both 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 can be found in the JSON format section.

  2. In 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:
    e.g.

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


Continue Reading

Developer Hub

File Formats

Did this answer your question?