miurla/babyagi-ui

Namespace values other than common are not translated

miurla opened this issue ยท 8 comments

./node_modules/next-i18next/dist/esm/config/createConfig.js 02:30:33.673 A Node.js API is used (process.cwd at line: 141) which is not supported in the Edge Runtime. 02:30:33.673 Learn more: https://nextjs.org/docs/api-reference/edge-runtime

Reference: #38 (comment)

I'm not sure about it, but maybe a solution is to remove the import type nextI18NextConfig from '../../next-i18next.config.js'; from the translate.ts.

import { i18n } from 'next-i18next';
import type nextI18NextConfig from '../../next-i18next.config.js';

type Namespace = 'common' | 'agent' | 'constants' | 'message';

export const translate = (
  key: string,
  text?: string | undefined | null,
  ns?: Namespace | null
) => {
  const opts = !!ns ? { ns } : undefined;
  const defaultText = text ? text : key;
  return i18n?.t(key, defaultText, opts) ?? key;
};

change to:

import { i18n } from 'next-i18next';

type Namespace = 'common' | 'agent' | 'constants' | 'message';

export const translate = (
  key: string,
  text?: string | undefined | null,
  ns?: Namespace | null
) => {
  const opts = !!ns ? { ns } : undefined;
  const defaultText = text ? text : key;
  return i18n?.t(key, defaultText, opts) ?? key;
};

I deployed and tried it and the error was gone, but I got the same symptoms.
I ran it locally to try and reproduce it, so it may be due to a change in the last commit.

436af45

One possible solution can be to change the nextI18NextConfig.ns as Array<string> to nextI18NextConfig.ns as string[]. I hope it will solve the problem, let me know if you are still facing with error or warning after changes.

Found the cause!
There was a place where translate("key", "defaultValue", 'namespace') was being used as translate("key", 'namespace'). Therefore, namespace would fall back to the default namespace common and the specified key would not be found. I'll fix it.

ex: https://github.com/miurla/babyagi-ui/pull/38/files#diff-6606af50826572564c9bd0c83ae35fee394fef80f5ba7ff1b36ac122fca8f00bR119

@Cs4K1Sr4C

I deployed your code ๐ŸŽ‰
Thank you again for your contribution. Your prompt response was very helpful.

I'd like to mention you in the update announcement, do you have a Twitter account? If so, please let me know.

@miurla

Thanks for the feedback!

The Translator module I wrote has some bugs and not so dynamic to handle automatically the missing key/value pairs etc..., but I'm working on it to makes the translations interactive mode.
Currently this is the working mechanism of the Translator module:
When there is a new static text to translate you can just easily use the translate("{key}", "{default text in English}", "{namespace}") syntax.
If you run the translator script (npm run translate) it will find and process the mentioned formula in every .ts and .tsx file;
It will extract "key/text/namespace" combinations into an array then translates the text to the selected target language.
So you can use en as source and en as target and it will create the complete English translation and its JSON files; After overwrite the old files - and move the new ones if they are - in the public/locales/en/ directory just easily run again the translator script with an other target language to create the desired complete translation.
When the extraction is done it will change the source code of the file - where from the translatable part has been extracted - to the single translate("{key}", "{namespace}") syntax.

I'm happy about that you could fix the error! ๐Ÿฅณ

Unfortunately I'm not a Twitter user (yet, already, yet... I don't know), but I appreciate your mention willingness with a link or just simply using my nick. ๐Ÿ™

I'm following this project, so if I have something, you will be notified, and soms I'll take a look on translations and other upgrades too... ๐Ÿ˜ธ ๐Ÿฆพ ๐Ÿค– ๐Ÿ‘

@Cs4K1Sr4C

OK! I'll introduce you using the link ๐Ÿ“ข
And the translator is great. Thank you for improving it. I'll check the PR ๐Ÿซก

Indeed, it's like a Translator Agent! Isn't it amazing to have an agent on the code side of the autonomous agent (BabyAGI) product? Apart from this PR, if you don't mind, I'd like to have a casual chat about expanding the Translator Agent. What tool should we use? Should we create a Discord for BabyAGI-UI?

@miurla

Thank you very much, great cooperation! ๐Ÿ™ Mine is the honor to be a member of this project too especially of this development process and in the future, I will be happy to lend a helping hand in the development of the project as my time โฐ, competence ๐Ÿ’ช, and energy โšก allow.

I'm 100% active ๐Ÿ”ฅ and most of the time 0/24 available on Discord. It would be great if you can also move there with the project. There are a lot of users ๐Ÿ‘ฅ and a perfect platform for the marketing ๐Ÿ“ฃ and for growing the community ๐ŸŒ who are interested in the BabyAGI and BabyAGI-UI.

By all means, let's continue a conversation about the module, because BabyAGI is not the first project it has been integrated into... more precisely, it is the first in its form. I have already created a repository ๐Ÿ—„๏ธ and I would like to create it as a node module which can be installed by npm install ๐Ÿ“ฆ