Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sudden "Attempted to call a translation function without setting a locale." errors after upgrading from 5.1.2 to 5.2 #2173

Closed
tobimori opened this issue Feb 1, 2025 · 2 comments

Comments

@tobimori
Copy link

tobimori commented Feb 1, 2025

Describe the bug
After upgrading the Lingui version, I suddenly get the following error:

Error: Lingui: Attempted to call a translation function without setting a locale.
Make sure to call `i18n.activate(locale)` before using Lingui functions.
This issue may also occur due to a race condition in your initialization logic.

To Reproduce
In entry.server.tsx and entry.client.tsx, I do call:

	const { messages } = await import(`../locales/${locale}.po`)
    i18n.loadAndActivate({ locale, messages })

In my routes I have several "top level" variables (not defined in loader/action or the react component) that use macros, like:

const columns = [
	{ name: t`Name`, width: 25, id: 'name', icon: 'rename', isRowHeader: true, allowsSorting: true },
] as const satisfies Columns

They might be the cause of this. I have 100s of those in the app and they worked fine with a previous lingui version.

In case you're clueless about this, I'm happy to tinker together a reproducible example.

Expected behavior
Same behaviour in 5.2 as in 5.1.2.

Additional context
React Router 7 + Vite app with vite-plugin-babel-macros & @lingui/vite-plugin

@tobimori
Copy link
Author

tobimori commented Feb 1, 2025

Right, I should've looked in the release notes... The error was purposefully introduced in #2131.
This is a huge breaking change for me, I have not noticed any issues with my usage of Lingui.

Maybe they could be a way to disable it using a compiler flag?

@tobimori
Copy link
Author

tobimori commented Feb 1, 2025

@tobimori tobimori closed this as completed Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant