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

Consider using a signal-like/reactive interface for translations #26

Open
macarie opened this issue Feb 9, 2024 · 1 comment
Open
Labels
enhancement New feature or request spike Requires exploring potential solutions t Changes regarding the `t` package

Comments

@macarie
Copy link
Member

macarie commented Feb 9, 2024

With a nanostores-like interface:

const { locale, translations, t, useTranslations } = defineTranslationsConfig(...)

locale.listen((locale) => {
	console.log('new locale set:', locale)
})

translations.listen((translations) => {
	valibot.setGlobalMessage((issue) => t(translations.errors.generic, { input: issue.message }))
})

console.log(
	t(
		await (translations.get())
			.article
			.heading
			.publishedBy,
		{ ... }
	)
)

const Component = () => {
	const heading = useTranslations(translations, 'article.heading')
	// or like it is now
	const heading = useTranslations('article.heading')

	return <span>{t(heading.publishedBy, { name })}</span>
}

With this interface, it's possible to remove the get* functions and builders, greatly simplifying both the t package and the adapters (~> also allowing the removal of the setup parameter).

@macarie macarie added enhancement New feature or request spike Requires exploring potential solutions t Changes regarding the `t` package labels Feb 9, 2024
@macarie
Copy link
Member Author

macarie commented Feb 9, 2024

This feature would also solve #17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request spike Requires exploring potential solutions t Changes regarding the `t` package
Projects
None yet
Development

No branches or pull requests

1 participant