# General Translation Python SDKs: hash_message URL: https://generaltranslation.com/en-US/docs/python/reference/functions/hash-message.mdx --- title: hash_message description: Hash an ICU MessageFormat string for translation lookup in General Translation Python. API reference for hash_message. --- Hashes an ICU MessageFormat string into the hex key used to look up its translation. This is the same hash [`t`](/docs/python/reference/functions/t) computes internally, so you can use it to build or inspect a translation dictionary. ## Overview [#overview] Call `hash_message` with a source string and optional keyword-only context, id, and max-chars. It indexes the message's variables, then hashes it with `data_format="ICU"`. ```python from gt_i18n import hash_message h = hash_message("Hello, world!") ``` Signature: ```python hash_message( message: str, *, context: str | None = None, id: str | None = None, max_chars: int | None = None, ) -> str ``` Import `hash_message` from `gt_i18n`. It is not re-exported by the framework packages. ## How it works [#how-it-works] - **Index variables.** It first normalizes the message by indexing its variables, so equivalent messages hash the same way. - **Hash.** It hashes the normalized message together with `context`, `id`, and `max_chars`, matching the JS gt-i18n implementation. Changing any of these produces a different hash. ## Parameters [#parameters] | Parameter | Description | Type | Optional | Default | | --- | --- | --- | --- | --- | | [`message`](#message) | The ICU MessageFormat source string. | `str` | No | — | | [`context`](#context) | Context string for disambiguation. | `str \| None` | Yes | `None` | | [`id`](#id) | Explicit message identifier. | `str \| None` | Yes | `None` | | [`max_chars`](#max-chars) | Maximum character constraint. | `int \| None` | Yes | `None` | ### `message` [#message] **Type** `str` · **Required** The ICU MessageFormat source string to hash. ### `context` [#context] **Type** `str | None` · **Optional** · **Default** `None` Optional context (the `_context` option in `t`), used to disambiguate identical source text. ### `id` [#id] **Type** `str | None` · **Optional** · **Default** `None` Optional explicit message identifier (the `_id` option in `t`). ### `max_chars` [#max-chars] **Type** `int | None` · **Optional** · **Default** `None` Optional maximum character constraint (the `_max_chars` option in `t`). ## Returns [#returns] **Type** `str` A hex hash string used as the translation lookup key. ## Example [#example] ```python from gt_i18n import hash_message # Build a translation dictionary keyed by hash translations = { hash_message("Hello, world!"): "Hola, mundo!", } ```