Closed trajano closed 1 year ago
What I did was create a wrapper as well
const t = useCallback(
(scope: Scope, options?: TranslateOptions) => {
// this conditional allows for the short form.
if (Array.isArray(scope)) {
return i18n.t(
scope.filter((p) => p.length > 0),
options
);
} else {
return i18n.t(scope, options);
}
},
[i18n, locale]
);
This allows for something like
const loginButtonText = useMemo(() => username.length > 0 ? t`loginAs${{ username }}` : t`login`, [t, username])
The filter was needed because
t`loginAs${{ username }}`
translates to add an empty string.
t ( ["loginAs", ""], { username })
I don't want to explicitly add support to templated strings as it's too complicated. I think creating a wrapper, as you did, is the way to go.
You don't have to create an explicit support for it, but the more correct typing is to make it ReadOnly
Ah okay so the JS code is in https://github.com/fnando/i18n
It's all good. I don't mind handling those issues here as well. :)
I was trying to figure out where the JS code was since I couldn't find it in this repo (with the -js
suffix)
There's history there. i18n-js repo used to have both Rails/Ruby code and the JS code. I broke both apart but didn't want to get riddle of the history of this repo, so in short, it's a mess. hahahaha
Description
I am looking for the code so I can PR but I can't seem to find it.
Anyway ...
Should be
This will allow us to have a construct
Which is being prevented by typescript because
Scope
's array form is mutable.