Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while using typesafe-i18n plugin #7

Closed
felixhaeberle opened this issue Jun 13, 2023 · 1 comment
Closed

error while using typesafe-i18n plugin #7

felixhaeberle opened this issue Jun 13, 2023 · 1 comment

Comments

@felixhaeberle
Copy link
Collaborator

Problem

stack trace: 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:

Cannot find module 'data:application/javascript,const%20de%20%3D%20%7B%0A%20%20%20%22title%22%3A%20%22typesafe-i18n%20-%20Svelte%20Herbst%20Summit%20%7Byear%3Aunknown%7D%22%2C%0A%20%20%20%22welcome%22%3A%20%22Willkommen%20zum%20Svelte%20Herbst%20Summit%20%7Byear%3Aunknown%7D%22%2C%0A%20%20%20%22spectators%22%3A%20%22%7B0%3Aunknown%7D%20Zuschauer%20live%22%2C%0A%20%20%20%22summit%22%3A%20%7B%0A%20%20%20%20%20%20%22schedule%22%3A%20%22%7B0%3Aunknown%7CsimpleDate%7D%22%0A%20%20%20%7D%2C%0A%20%20%20%22log%22%3A%20%22Dieses%20Logging%20wurde%20von%20'%7BfileName%3Aunknown%7D'%20aufgerufen%22%0A%7D%0A%0Aexport%20default%20de'
Require stack:
- 

---

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 (/Users/felixhaberle/Desktop/git/inlang/source-code/core/src/config/setupConfig.ts:31:9)
    at main (/Users/felixhaberle/Desktop/git/inlang/source-code/ide-extension/src/main.ts:89:17)
    

Expected behavior

Should work.

Used config

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

return {
  plugins: [typesafeI18nPlugin()],
  ideExtension: {
    messageReferenceMatchers: [
      async (args) => {
        const regex = /\$LL\.[a-zA-Z]+\([^)]*\)/gm;
        const str = args.documentText;
        let match;
        const result = [];

        while ((match = regex.exec(str)) !== null) {
          const startLine = (str.slice(0, Math.max(0, match.index)).match(/\n/g) || []).length + 1;
          const startPos = match.index - str.lastIndexOf("\n", match.index - 1);
          const endPos = match.index + match[0].length - str.lastIndexOf("\n", match.index + match[0].length - 1);
          const endLine = (str.slice(0, Math.max(0, match.index + match[0].length)).match(/\n/g) || []).length + 1;

          result.push({
            messageId: match[0],
            position: {
              start: {
                line: startLine,
                character: startPos,
              },
              end: {
                line: endLine,
                character: endPos,
              },
            },
          });
        }
        return result;
      },
    ],
    extractMessageOptions: [
      {
        callback: (messageId) => {
          const lastDotIndex = messageId.lastIndexOf(".");
          const functionName = `$LL.${messageId.substring(0, lastDotIndex)}`;
          const argument = messageId.substring(lastDotIndex + 1);
          return `${functionName}(${argument})`;
        },
      },
    ],
    documentSelectors: [
      {
        language: "javascript",
      },
      {
        language: "typescript",
      },
      {
        language: "svelte",
      },
    ],
  }
}
}
@ivanhofer
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants