opral / inlang-sherlock

Issue tracker for Sherlock
https://marketplace.visualstudio.com/items?itemName=inlang.vs-code-extension
2 stars 0 forks source link

"ERROR: … not found in source with" when using translations with different namespaces in the same file. #56

Closed typeofweb closed 1 month ago

typeofweb commented 1 month ago

Environment

project.inlang/settings.json

{
    "$schema": "https://inlang.com/schema/project-settings",
    "sourceLanguageTag": "en",
    "languageTags": ["en", "de"],
    "modules": ["https://cdn.jsdelivr.net/npm/@inlang/plugin-next-intl@latest/dist/index.js"],
    "plugin.inlang.nextIntl": {
        "pathPattern": "./messages/{languageTag}.json"
    }
}

Code

import { getTranslations } from "next-intl/server";

export const C1 = async () => {
    const t = await getTranslations("/cart");
    return t("empty.title");
};
export const C2 = async () => {
    const t = await getTranslations("/product");
    return t("page.imagesTitle");
};

Result

There's an error reported on line t("page.imagesTitle") "ERROR: … not found in source with" even though the invocation is correct and works.

felixhaeberle commented 1 month ago

@typeofweb Hi, thanks for opening the issue.

I currently do not understand what you are doing with the argument of /chart & /product.

According to the docs, this is not a "Link field", but a regular string. https://next-intl-docs.vercel.app/docs/environments/server-client-components#async-components

Regardless, if your key is then also /cart.empty.title or /product.page.imagesTitle this should work.

But I'm assuming in your language file, this is just cart or product. As you can probably imagine, the (concat) string has to be a perfect match.

See also: it("should add the defined namespace by useTranslations hook", async () => {

typeofweb commented 1 month ago

Here's my language file (simplified):

{
    "/product": {
        "page": {
            "imagesTitle": "Images"
        }
    },
    "/cart": {
        "empty": {
            "title": "Your cart is empty"
        }
    }
}

Everything in next-intl and TypeScript is fine, and the matches are perfect. It's just the vscode extension that reports a problem, and only if t is initialized multiple times in the same file with different arguments.

Not sure why this issue was closed, it's not fixed.

felixhaeberle commented 1 month ago

Sorry for closing too early! I see. The second hook namespace isn't properly addressed to the respective t function. Let me inspect this real quick.

felixhaeberle commented 1 month ago

fix in https://github.com/opral/monorepo/pull/2858