tolgee / tolgee-cli

The Tolgee CLI
MIT License
16 stars 11 forks source link

fix: properly extract escaped characters and respect default namespace in magic comments #91

Closed stepan662 closed 3 months ago

github-actions[bot] commented 3 months ago

:tada: This PR is included in version 2.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

OrenChapo commented 3 months ago

Seems like --default-namespace is still ignored in @tolgee-key comments in v2.1.1. Example code:

// @tolgee-key { "ns": "ui", "key": "errors.cy1001", "defaultValue": "User not found." }

(the above comment works as expected, ui namespace assumed)

// @tolgee-key { "key": "errors.cy1001", "defaultValue": "User not found." }

(the above comment doesn't work; it assumes default namespace instead of ui)

tolgee sync --default-namespace ui -pt "./src/**/*.ts" "./src/**/*.vue"

(the above is the command I run).

Maybe the issue is specific to JSON comments? Or maybe it happens when there's no t function at all? Try to add this test (copy-pasted-and-modified your test):

    it('respects default namespace in magic comments with JSON', async () => {
      const report = await getReport(
        `
        // @tolgee-key { "key": "key-override", "defaultValue": "Default Text." }
        `,
        FILE_NAME,
        'react',
        { defaultNamespace: 'namespace' }
      );

      expect(report.keys).toEqual([
        { keyName: 'key-override', namespace: 'namespace', defaultValue: 'Default Text.', line: 2 },
      ]);
    });
stepan662 commented 3 months ago

Ah you are right, I've fixed in on only one place, but the case when it doesn't override anything in code was treated separately. So I've unified the cases into one function, where it's fixed.

https://github.com/tolgee/tolgee-cli/pull/94

OrenChapo commented 3 months ago

I confirm #94 fixes my issue. Thanks again Stephan!