ivanhofer / inlang-plugin-typesafe-i18n

the official `typesafe-i18n` plugin for `inlang`
MIT License
11 stars 2 forks source link

Error when using plugin #8

Closed Suyashtnt closed 8 months ago

Suyashtnt commented 1 year ago

I have the following config:

/**
 * @type {import("@inlang/core/config").DefineConfig}
 */
export async function defineConfig(env) {
    const {default: typesafeI18nPlugin} = await env.$import(
        'https://cdn.jsdelivr.net/gh/ivanhofer/inlang-plugin-typesafe-i18n@2.3.0/dist/index.js'
    );

    const {default: standardLintRules} = await env.$import(
        'https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@2/dist/index.js'
    );

    return {
        plugins: [typesafeI18nPlugin({}), standardLintRules()]
    };
}

running npx @inlang/cli config validate gives the following error:

ERROR  Error: The inlang.config.js is invalid.                                                                                                                                                  13:15:15

# The following errors occurred during the setup of plugins:

None ✅

# The following errors occurred during the validation of the config:

Unexpected identifier

---

If plugins return errors, chances are high that the plugin errors are the root cause
for the config errors. Try to fix the plugin errors first.

    at setupConfig (file:///home/tntman/.npm/_npx/657dfa428a72cbef/node_modules/@inlang/cli/dist/main.js:68539:11)
    at async getConfig (file:///home/tntman/.npm/_npx/657dfa428a72cbef/node_modules/@inlang/cli/dist/main.js:68657:19)
    at async file:///home/tntman/.npm/_npx/657dfa428a72cbef/node_modules/@inlang/cli/dist/main.js:69441:22
ivanhofer commented 1 year ago

@felixhaeberle I was not able to follow the latest changes from the past weeks. Could you please take a look at this issue? Or assign someone else?

felixhaeberle commented 1 year ago

@ivanhofer I haven't seen this error before and am currently blocked by other tasks. Can you probably check if you can reproduce this once you have time?

Furthermore, we have to decide if we move the plugin into the inlang monorepo to official support it & have it under one unified quality control (tests in the monorepo). We did the same with the plugin-json and the plugin-i18next, so it would be helpful also to move this one.

I'll keep me assigned to not forget about it and come back later.

In the meantime, it would be nice if you could reproduce the error, as I'm not familiar with typesafe-i18n or this plugin – we could then fix it together if an action from the CLI is needed.

Suyashtnt commented 1 year ago

@ivanhofer I haven't seen this error before and am currently blocked by other tasks. Can you probably check if you can reproduce this once you have time?

Furthermore, we have to decide if we move the plugin into the inlang monorepo to official support it & have it under one unified quality control (tests in the monorepo). We did the same with the plugin-json and the plugin-i18next, so it would be helpful also to move this one.

I'll keep me assigned to not forget about it and come back later.

In the meantime, it would be nice if you could reproduce the error, as I'm not familiar with typesafe-i18n or this plugin – we could then fix it together if an action from the CLI is needed.

For me, I'm in a new sveltekit typescript project and I used the default typesafe- i18n config (using the cli and --setup-auto) and plugin, and then I setup inlang using the config I provided earlier

ivanhofer commented 1 year ago

The issue should be fixed in version 2.4.0. Let me know if you still have issues.

SeanLatimer commented 1 year ago

The issue should be fixed in version 2.4.0. Let me know if you still have issues.

I seem to be running into this issue on v2.4.0 at the moment

This happens on a fresh kit skeleton.

npm i typesafe-i18n
npm run typesafe-i18n -- --setup-auto
npx @inlang/cli@latest config init
npx @inlang/cli@latest config update
npx @inlang/cli@latest config validate
❯ pnpx @inlang/cli@latest config validate
../../../.pnpm-store/v3/tmp/dlx-31712    |   +1 +
../../../.pnpm-store/v3/tmp/dlx-31712    | Progress: resolved 1, reused 1, downloaded 0, added 1, done

 ERROR  The inlang.config.js is invalid.

# The following errors occurred during the setup of plugins:

None ✅

# The following errors occurred during the validation of the config:

Unexpected identifier

---

If plugins return errors, chances are high that the plugin errors are the root cause

  # The following errors occurred during the setup of plugins:

  None ✅

  # The following errors occurred during the validation of the config:

  Unexpected identifier

  ---

  If plugins return errors, chances are high that the plugin errors are the root cause
  for the config errors. Try to fix the plugin errors first.

  at setupConfig (/G:/.pnpm-store/v3/tmp/dlx-31712/node_modules/.pnpm/@inlang+cli@0.13.3/node_modules/@inlang/cli/dist/main.js:68914:11)
  at async getConfig (/G:/.pnpm-store/v3/tmp/dlx-31712/node_modules/.pnpm/@inlang+cli@0.13.3/node_modules/@inlang/cli/dist/main.js:69029:19)
  at async Command2.validateCommandAction (/G:/.pnpm-store/v3/tmp/dlx-31712/node_modules/.pnpm/@inlang+cli@0.13.3/node_modules/@inlang/cli/dist/main.js:70686:37) 
/**
 * @type {import("@inlang/core/config").DefineConfig}
 */
export async function defineConfig(env) {
  const { default: typesafeI18nPlugin } = await env.$import(
    'https://cdn.jsdelivr.net/gh/ivanhofer/inlang-plugin-typesafe-i18n@2.4.0/dist/index.js'
  );

  const { default: standardLintRules } = await env.$import(
    'https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@2/dist/index.js'
  );

  return {
    referenceLanguage: 'en',
    plugins: [typesafeI18nPlugin(), standardLintRules()]
  };
}
ivanhofer commented 1 year ago

Can you please share the contents of your translation files? Note: inlang currently does a refactoring on how plugins work, so I need to wait until it is completed in order to see how to adapt this plugin.

SeanLatimer commented 1 year ago

I found the source of the issue.

typesafe-i18n has been generating files like this, using the satisfies keyword.

const en = {
  // TODO: your translations go here
  HI: 'Hi {name:string}! Please leave a star if you like this project: https://github.com/ivanhofer/typesafe-i18n',
} satisfies BaseTranslation;

Changing the type to this, does work however

const en: BaseTranslation = {
  // TODO: your translations go here
  HI: 'Hi {name:string}! Please leave a star if you like this project: https://github.com/ivanhofer/typesafe-i18n',
};
ivanhofer commented 1 year ago

satisfies should actually work already. I'll take a look at this after the refactoring of inlangs plugin structure.