Feature Request: CLI-powered TypeScript type generation from Tolgee platform keys #3559
Replies: 1 comment
|
Thanks for this feature request, this is an amazing idea! 🙏 We appreciate you taking the time to describe it so thoroughly. One thing I wanted to mention though. In general, we don't recommend reusing the same translation keys across different contexts. Even if two buttons say "Confirm" today, they might need different translations in other languages or evolve differently over time. Keeping keys tied to their specific context (like dialog.confirmButton vs common.confirm) gives translators more flexibility and avoids situations where changing one translation accidentally breaks another place in the UI. That said, the TypeScript type generation itself is still a great idea for catching typos and improving discoverability. Would you be up for submitting a PR for this? 🙏 The CLI lives in the tolgee-cli repo. We'd be happy to help guide you through the codebase if needed. |
Uh oh!
There was an error while loading. Please reload this page.
Feature Request: CLI-powered TypeScript type generation from Tolgee platform keys
Problem
When multiple developers work on a project, translation keys inevitably get duplicated with slightly different names because
keyNameis a plain string with no discoverability at authoring time.Real examples from our project (~800+ keys):
common.confirmvsdialog.confirmButtonvsbutton.confirmerror.networkErrorvscommon.networkFailedvstoast.connectionErrorThe existing
tolgee.d.tsapproach (importing a local JSON and usingDotNotationEntries) helps with autocomplete for existing keys, but it has limitations:tolgee pull. If another developer just created keys on the platform, you won't see them.LiteralUnionintentionally allows arbitrary strings, so typos and duplicates still slip through.Proposed Solution
Add a
tolgee typegen(or integrate intotolgee pull) CLI command that:.d.tsfile with a strictPathValuestype representing all valid dot-notation key paths.LiteralUnionfallback), forcing developers to register keys on the platform first.Benefits
tolgee typegen --checkcan fail CI if types are stale, ensuring the codebase stays in sync.Prior Art
next-intlgenerates TypeScript types from message files with full path autocomplete.typesafe-i18ngenerates types from a master locale file.typesafe-i18n-like support (ref: Tolgee blog, 2022).Suggested Implementation Path
tolgee typegen(or--typegenflag ontolgee pull).tolgeercfor project config (API key, namespaces)/v2/projects/{id}/translations/select-all).d.tsto a configurable path--strictflag to omitLiteralUnionwrapper--checkflag for CI (exit 1 if generated file differs from committed file)Environment
All reactions