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.
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.
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.
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... ๐ธ ๐ฆพ ๐ค ๐
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?
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
๐ฆ