# General Translation Python SDKs: Declaring variables and variants URL: https://generaltranslation.com/en-GB/docs/python/guides/declaring-variables.mdx --- title: Declaring variables and variants description: How to preserve dynamic values and generate finite variants with General Translation declare_var, derive, and decode_vars in Python. related: links: - /docs/python/guides/translating-strings - /docs/python/guides/detecting-locale - /docs/python/guides/configuring - /docs/python/guides/storing-translations --- Some values within a translated string should not themselves be translated. The Python SDK gives you two markers for this: [`declare_var`](/docs/python/reference/functions/declare-var) for genuinely dynamic values, and [`derive`](/docs/python/reference/functions/derive) for a value with a small, fixed set of outcomes. ## Preserve a dynamic value with `declare_var` [#declare-var] Wrap a runtime value — a user name, an email, a count — with `declare_var` so it is embedded in the message and preserved rather than translated. It returns an ICU `{_gt_, select, ...}` construct you place inside a [`t`](/docs/python/reference/functions/t) call. ```python from gt_flask import t, declare_var t(f"Signed in as {declare_var(email, name='email')}") ``` The optional `name` is a human-readable label for the variable, useful for translators and for [`decode_vars`](/docs/python/reference/functions/decode-vars). ## Generate finite variants with `derive` [#derive] When a sentence embeds a value with a small, fixed set of outcomes, translating it once is not enough — other languages inflect the surrounding words differently for each outcome. `derive` marks such a value so the CLI generates a separate translation for every variant. At runtime, `derive` returns its input unchanged; at extraction time, the CLI produces one entry per outcome. ```python from gt_flask import t, derive gender = "male" t(f"The {derive('boy' if gender == 'male' else 'girl')} is playing.") # Generates: "The boy is playing." and "The girl is playing." ``` Each variant is translated independently, so every version reads naturally in every language. *Note: Keep the set of derived outcomes small. Each additional `derive` call multiplies the number of generated entries.* ## Combine the two [#combine] Inside a derived sentence you can still embed a genuinely dynamic value with `declare_var`, so it is preserved rather than translated. ```python from gt_flask import t, derive, declare_var t(f"{declare_var(name, name='name')} adopted a {derive('cat' if is_cat else 'dog')}.") ``` ## Recover embedded values with `decode_vars` [#decode] [`decode_vars`](/docs/python/reference/functions/decode-vars) replaces `{_gt_, select, other {value}}` constructs in a string with their embedded values — useful when you need the plain, filled-in string back from a marked one. ```python from gt_i18n import declare_var, decode_vars marked = f"Signed in as {declare_var('a@b.com', name='email')}" decode_vars(marked) # "Signed in as a@b.com" ``` *Note: [`declare_static`](/docs/python/reference/functions/declare-static) is a deprecated alias for `derive` kept for backwards compatibility. Use `derive` in new code.* ## Next steps - /docs/python/guides/translating-strings - /docs/python/guides/detecting-locale - /docs/python/guides/configuring - /docs/python/guides/storing-translations