Skip to content

Stabilize useExtracted #2087

@amannn

Description

@amannn

With next-intl@4.5, there's now experimental support for useExtracted.

The next phase will be to collect feedback, fix bugs, potentially incorporate changes and fill in the gaps for missing features and docs.

TODO

  • "Frozen" mode? (ref)
  • Could be that some change events are dropped (ref)
  • Ensure extraction runs before build (ref)
  • addDependency / addContextDependency instead of watcher?
  • Options for excluding line numbers? (ref, ref)
  • useExtracted auto-generated message keys starting with / cause Google crawler 404 errors #2250
  • Support calling await getExtracted with Promise.all?
  • Docs/demo for monorepos (ref)
    • Not shared messages (transpilePackages: ['@acme/ui'] can be used, but not necessarily)
    • Shared messages (what if consumers build messages themselves after running extraction script? (ref))
  • Docs about not touching target locales (but only extract to source catalog)
  • Docs about static analyzability (check if errors are thrown)
  • SWC plugins are "experimental" (see Remove JS-based loader bridge for SWC plugin of useExtracted to further improve transform performance #2187)
  • Autocomplete with type augmentation, but allow new messages (ref). It doesn't work for .po unfortunately though.
  • We should mention in docs that messages are read during build (this might be non-obvious).
  • Think more about fallbacks (ref). Should we treat empty messages as errors in next-intl? This would be a minor breaking change. People can guard against this though with t.has.
  • Reconsider msgid for .po to be ID or source message (ref 1, ref 2). Should we accept ID-less messages and generate them on demand?
  • Ask for more feedback
    • Node.js website team

Future explorations

  • How to migrate from hand-crafted keys to autogenerated ones (Codemod? Contributions are welcome)
  • A way to migrate catalogs when changing the format
  • Tool calls for get all missing translations / translate missing / etc.
  • A way to fix source text, i.e. pick a message by key and migrate it to a new message that is synced back into source code (e.g. with an editor, or could we also just watch the source catalog and automatically sync to source?)
  • Validation that extracted message for source locale matches source code
  • ESLint rule that checks that you're not using dynamic expressions with t
  • Provide supplemental descriptions for translations automatically via AI (related: Crowdin Context Harvester)
  • Improve/add defaults
    • Detect srcPath automatically (like Tailwind)
    • Also all others could have defaults, but the question remains whether extraction remains opt-in
  • Remove JS-based loader bridge for SWC plugin of useExtracted to further improve transform performance #2187
  • Support for use-intl (related to ☂️ Umbrella: Support for other frameworks #1863)

This list acts as my personal todo list that I want to share for transparency, but please be sure to comment here if you have feedback for the feature:

#2036

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions