feat: add get_version_id() across gt-i18n, gt-fastapi, gt-flask#27
Merged
ErnestM1234 merged 4 commits intogeneraltranslation:mainfrom Mar 19, 2026
Merged
Conversation
Mirrors the useVersionId/getVersionId hook added to the JS packages in generaltranslation/gt#1121. - I18nManager: new version_id param + get_version_id() method - Config loader: reads _versionId from gt.config.json - Helper: get_version_id() convenience function - Re-exported from gt-i18n, gt-fastapi, gt-flask
| resolved_cache_url = cache_url or file_config.get("cache_url") | ||
| resolved_custom_mapping = custom_mapping or file_config.get("custom_mapping") | ||
|
|
||
| resolved_version_id = file_config.get("version_id") |
There was a problem hiding this comment.
version_id not passable as a direct parameter to initialize_gt()
resolved_version_id is read only from the config file — there is no version_id keyword argument on initialize_gt(). Every other configuration value (project_id, cache_url, default_locale, locales, custom_mapping) follows the pattern of accepting both a function argument (which takes precedence) and a file-config fallback. Users who want to set version_id programmatically — e.g. in tests or in apps that don't use gt.config.json — have no way to do so.
The same issue exists in packages/gt-flask/src/gt_flask/_setup.py at line 59.
Suggested fix (FastAPI — Flask is identical):
def initialize_gt(
app: Any,
*,
default_locale: str | None = None,
locales: list[str] | None = None,
custom_mapping: CustomMapping | None = None,
project_id: str | None = None,
cache_url: str | None = None,
version_id: str | None = None, # ← add
get_locale: Callable[..., str] | None = None,
load_translations: Callable[[str], dict[str, str]] | None = None,
eager_loading: bool = True,
config_path: str | None = None,
load_config: Callable[[str | None], GTConfig] | None = None,
) -> I18nManager:
...
resolved_version_id = version_id or file_config.get("version_id")
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/gt-fastapi/src/gt_fastapi/_setup.py
Line: 59
Comment:
**`version_id` not passable as a direct parameter to `initialize_gt()`**
`resolved_version_id` is read only from the config file — there is no `version_id` keyword argument on `initialize_gt()`. Every other configuration value (`project_id`, `cache_url`, `default_locale`, `locales`, `custom_mapping`) follows the pattern of accepting both a function argument (which takes precedence) and a file-config fallback. Users who want to set `version_id` programmatically — e.g. in tests or in apps that don't use `gt.config.json` — have no way to do so.
The same issue exists in `packages/gt-flask/src/gt_flask/_setup.py` at line 59.
Suggested fix (FastAPI — Flask is identical):
```
def initialize_gt(
app: Any,
*,
default_locale: str | None = None,
locales: list[str] | None = None,
custom_mapping: CustomMapping | None = None,
project_id: str | None = None,
cache_url: str | None = None,
version_id: str | None = None, # ← add
get_locale: Callable[..., str] | None = None,
load_translations: Callable[[str], dict[str, str]] | None = None,
eager_loading: bool = True,
config_path: str | None = None,
load_config: Callable[[str | None], GTConfig] | None = None,
) -> I18nManager:
...
resolved_version_id = version_id or file_config.get("version_id")
```
How can I resolve this? If you propose a fix, please make it concise.…-flask Greptile correctly identified that version_id was the only config value not passable as a direct parameter. Now follows the same pattern as project_id, cache_url, etc. — function argument takes precedence over file config fallback. Also adds changeset for the release.
ErnestM1234
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors the
useVersionId/getVersionIdhook added to the JS packages in generaltranslation/gt#1121.Changes:
I18nManager: newversion_idparam +get_version_id()method_versionIdfromgt.config.jsonget_version_id()convenience functiongt-i18n,gt-fastapi,gt-flaskinitialize_gt()in both FastAPI and Flask forwardsversion_idfrom configAll 105 existing tests pass.
Greptile Summary
This PR ports the
getVersionId/useVersionIdfeature from the JS packages to the Python SDK by threading aversion_idvalue through the config loader,I18nManager, and a new convenience helper function that is re-exported fromgt-i18n,gt-fastapi, andgt-flask.The core implementation is correct and the approach is consistent with existing patterns in the codebase. There is one notable inconsistency worth addressing before merging:
version_idnot exposed as a direct parameter ofinitialize_gt()(both FastAPI and Flask): unlike every other configuration value (project_id,cache_url,default_locale,locales,custom_mapping),version_idcan only be supplied viagt.config.json— there is no keyword argument oninitialize_gt()that would let users set it programmatically. This limits usability in environments that don't use the config file (e.g. tests, dynamic multi-tenant setups).I18nManagerclass docstring is missing an entry for the newversion_idconstructor parameter.Confidence Score: 3/5
version_idparameter oninitialize_gt()is an API inconsistency that should be fixed before shipping.gt.config.json. The score is reduced becauseinitialize_gt()in both FastAPI and Flask lacks aversion_idkeyword argument, making the new feature inaccessible to users who configure the manager programmatically — a clear inconsistency with the established pattern for all other parameters.packages/gt-fastapi/src/gt_fastapi/_setup.pyandpackages/gt-flask/src/gt_flask/_setup.pyboth need aversion_idparameter added toinitialize_gt().Important Files Changed
version_idparam toI18nManager.__init__and aget_version_id()accessor; implementation is correct but the class docstring is missing documentation for the new parameter.version_idfrom config file and forwards it toI18nManager, butinitialize_gt()does not expose aversion_idkeyword argument — breaking consistency with every other parameter that supports both programmatic and file-based configuration.gt-fastapi/_setup.py—version_idis only sourced from config, with no function-argument override available ininitialize_gt()._versionId→version_idmapping and theversion_id: strfield toGTConfig; clean and correct change.get_version_id; correctly placed in the public API and__all__.get_version_idto the FastAPI package's public re-exports; straightforward and correct.get_version_idto the Flask package's public re-exports; straightforward and correct.Sequence Diagram
sequenceDiagram participant App as Application participant Setup as initialize_gt() participant Config as load_gt_config() participant Manager as I18nManager participant Helper as get_version_id() participant Singleton as _singleton App->>Setup: initialize_gt(app, ...) Setup->>Config: load_gt_config(config_path) Config-->>Setup: GTConfig (incl. version_id from _versionId) Setup->>Manager: I18nManager(..., version_id=resolved_version_id) Manager->>Manager: self._version_id = version_id Setup->>Singleton: set_i18n_manager(manager) Setup-->>App: manager Note over App,Helper: Later, during request handling App->>Helper: get_version_id() Helper->>Singleton: get_i18n_manager() Singleton-->>Helper: manager Helper->>Manager: manager.get_version_id() Manager-->>Helper: self._version_id Helper-->>App: str | NoneComments Outside Diff (1)
packages/gt-i18n/src/gt_i18n/i18n_manager/_i18n_manager.py, line 20-33 (link)I18nManagerdocstring missingversion_idThe class-level docstring documents every constructor parameter except the newly added
version_id. This omission will make it harder for library consumers to discover the parameter.Prompt To Fix With AI
Prompt To Fix All With AI
Last reviewed commit: "feat: add get_versio..."