components-js icon indicating copy to clipboard operation
components-js copied to clipboard

I18N

Open rainbowflesh opened this issue 2 years ago • 6 comments

Describe the problem

Hope there have i18n entry.

Describe the proposed solution

Maintain a json file that contain i18n KV context / translate, for example: https://react.i18next.com/

export const useTranslate = () => {
    const { i18nProvider } = useContext("path/to/json.json");

    const fn = useMemo(() => {
        function translate(
            key: string,
            options?: any,
            defaultMessage?: string,
        ): string;
        function translate(key: string, defaultMessage?: string): string;

        function translate(
            key: string,
            options?: string | any,
            defaultMessage?: string,
        ) {
            return (
                i18nProvider?.translate(key, options, defaultMessage) ??
                defaultMessage ??
                (typeof options === "string" &&
                typeof defaultMessage === "undefined"
                    ? options
                    : key)
            );
        }

        return translate;
    }, [i18nProvider]);

    return fn;
};

Alternatives considered

No response

Importance

I cannot use LiveKit without it

Additional Information

No response

rainbowflesh avatar Apr 19 '23 09:04 rainbowflesh

Hi,

while i18n is very interesting, this would be a rather big endeavour.

Can you share a bit more about what you would like to achieve specifically? Are you using lower level components or the VideoConference prefab directly?

lukasIO avatar Apr 19 '23 12:04 lukasIO

Hi,

while i18n is very interesting, this would be a rather big endeavour.

Can you share a bit more about what you would like to achieve specifically? Are you using lower level components or the VideoConference prefab directly?

I tested both, and I found some component like <PreJoin /> allow override label; But prefabricated components like <ControlBar /> in line 126 give the showText a const value;

      {visibleControls.leave && (
        <DisconnectButton>
          {showIcon && <LeaveIcon />}
          {showText && 'Leave'}
        </DisconnectButton>
      )}

I'm attempting to make some of these components i18nlized such as {showText && translate("buttons.leave")}, however it may not an elegant solution because I was creating duplicate components. It could be helpful if showText have value from overridable labels.

Or, am I missing some hacky function to inject i18n value to showText 🤔? Please forgive me, Im not professional in front end.


Edit: I had a quick thought: Could I replace these components with overridable labels like <PreJoin/> then PR, is that reasonable? If not, please let me know ;).

rainbowflesh avatar Apr 19 '23 16:04 rainbowflesh

for the control bar you cannot inject it right now, but you can always do something like

<DisconnectButton>
{t('disconnect-button')}
<DisconnectButtion>

with your own translate implementation.

We'll think more about how to make this easier for users in the future

lukasIO avatar May 03 '23 14:05 lukasIO

can I set up labels in config somehow?

AlexanderKozhevin avatar May 24 '24 20:05 AlexanderKozhevin

Yeah, that would be a really nice option for us danes :) <3

runekaagaard avatar Jan 20 '25 12:01 runekaagaard