ivanhofer / inlang-plugin-typesafe-i18n

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

`sdk` property is missing in your `inlang.config.js` #4

Closed omar2205 closed 1 year ago

omar2205 commented 1 year ago

I followed both the getting started guides and used the inlang.config.js in this repo. It spat a lot of minified JS, and this:

Yo [Error]: The `sdk` property is missing in your `inlang.config.js` file.`. 
Make sure to use the `sdkPlugin` in your `inlang.config.js` file.
ivanhofer commented 1 year ago

What are you trying to achive? Do you want to use typesafe-i18n or the inlang SDK?

omar2205 commented 1 year ago

I'm trying to use typesafe-i18n plugin with Inlang.

omar2205 commented 1 year ago

So I can't use inlang-plugin-typesafe-i18n with the SDK?

ivanhofer commented 1 year ago

Yes you can, but it does not make much sense in my opinion. typesafe-i18n is primarly a library and if you use the inlang SDK, you will not use it as a library anymore. Just for storing translations in a TypeScript file. typesafe-i18n has features that are currently not available in ìnlang. Therefore the plugin has also some limitations.

It seems you are using an older version of @inlang/sdk-js that does not include the link to the docs in the error message. You need to add the sdkPlugin in order to be able to use the inlang SDK: https://inlang.com/documentation/sdk/configuration

sudo-sand commented 1 year ago

Wait, how do you use this with inlang? Because like @omar2205 I followed the getting started guide and I'm getting the same sdk missing error. Can you create a simple repo of brand new Sveltekit project and set this up?

ivanhofer commented 1 year ago

please share your inlang.config.js

sudo-sand commented 1 year ago
/**
 * @type {import("@inlang/core/config").DefineConfig}
 */
export async function defineConfig(env) {
    const { default: sdkPlugin } = await env.$import(
        'https://cdn.jsdelivr.net/npm/@inlang/sdk-js-plugin@0.4.4/dist/index.js'
    );
    // initialize the plugin
    const { default: typesafeI18nPlugin } = await env.$import(
        'https://cdn.jsdelivr.net/gh/ivanhofer/inlang-plugin-typesafe-i18n@2.3/dist/index.js'
    );

    return {
    referenceLanguage: "en",
        plugins: [
            typesafeI18nPlugin(),
            sdkPlugin({
                languageNegotiation: {
                    strategies: [{ type: 'localStorage' }]
                },
                resources: {
                    cache: 'Build-time'
                }
            })
        ]
    };
}
ivanhofer commented 1 year ago

Looks correct. What is not working? What error do you get?

sudo-sand commented 1 year ago

When I run npm dev I get the same error as above:

Yo [Error]: The `sdk` property is missing in your `inlang.config.js` file.`. Make sure to use the `sdkPlugin` in your `inlang.config.js` file.
ivanhofer commented 1 year ago

What version of the SDK have you installed?

ivanhofer commented 1 year ago

You probably haven't read the full error message:

Vs [Error]: Failed to setup plugin 'inlang.sdk-js':

[
  {
    "received": "Build-time",
    "code": "invalid_literal",
    "expected": "build-time",
    "path": [
      "resources",
      "cache"
    ],
    "message": "Invalid literal value, expected \"build-time\""
  }
]

remove those lines and it should work:

resources: {
    cache: 'Build-time'
}

There is a typo in the docs and Build-time should actually be build-time and therefore the setup fails. I have fixed the documentation and it should be live in a couple of minutes.

sudo-sand commented 1 year ago
"@inlang/core": "^0.8.3",
"@inlang/sdk-js": "^0.4.4",

yeah build-time fixed it

omar2205 commented 1 year ago

build-time fixed it for me, too. I don't have any "type safety" tho.

ivanhofer commented 1 year ago

That's a well known issue with url imports https://github.com/inlang/inlang/issues/689

omar2205 commented 1 year ago

OK, thanks!

I meant in the i function

omar2205 commented 1 year ago

I meant in the i function, I don't have any hints. image

ivanhofer commented 1 year ago

This is not implemented at the moment. I have created an issue where you can subscribe to: https://github.com/inlang/inlang/issues/754

samuelstroschein commented 1 year ago

@sudo-sand FYI as Ivan said though, you shouldn't use sdkPlugin and the typesafe-i18n-plugin at the same time. Both plugins provide an i18n lib. You only need one.

We are updating the communication this week. If you can explain where the confusion is coming from, we can improve the docs right away :)

sudo-sand commented 1 year ago

@samuelstroschein I thought typesafe-i18n-plugin is an extra plugin to be used. Like JSON reader. Because its here https://github.com/inlang/ecosystem#resources

You're saying I don't have to use typesafe-i18n-plugin? I just follow this guide https://inlang.com/documentation/sdk/sveltekit? That guide tell me how to set up the translations files.

ivanhofer commented 1 year ago

@sudo-sand yes, you can use both, but it does not make that much sense. The typesafe-i18n-plugin is primarly meant for already existing projects that use typesafe-i18n as a library but want to use the inlang editor to update translations.

If you want to store translations in a .json file you can use the json-plugin.

ivanhofer commented 1 year ago

I made two commits to make this more clear: https://github.com/inlang/ecosystem/commit/fc036691766d7da8d94e7a1171ff95e95e86f4f8 https://github.com/ivanhofer/inlang-plugin-typesafe-i18n/commit/8e0b8750165a1d08e98887cafcbfcbc5aaa7cb73