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

Dynamic variable name with square brackets breaks extract command #2159

Closed
FelixMalfait opened this issue Jan 26, 2025 · 11 comments
Closed

Dynamic variable name with square brackets breaks extract command #2159

FelixMalfait opened this issue Jan 26, 2025 · 11 comments

Comments

@FelixMalfait
Copy link
Contributor

We're in the process of implementing lingui on https://github.com/twentyhq/twenty. Really great experience so far, thank you!

I've encountered an issue when running the lingui extract command with dynamic variable names like here.
https://github.com/twentyhq/twenty/pull/9847/files/cf631f5abdf180b408b56c37c4f279c654d16c19#diff-dca629c9ae348f7bbcb4378298f48cb702f59e2a965c0956f2ea4d2f0ecb6301

It worked when I replaced them by their static value.
Image

Is there a way to fix the parser to allow for these?

Thanks a lot!

@vonovak
Copy link
Collaborator

vonovak commented Jan 26, 2025

Hello, can you share what issue you have encountered specifically?

@FelixMalfait
Copy link
Contributor Author

Hey sorry, I should have shared it earlier.

Image

⠼ Cannot process file /Users/felixmalfait/Projects/twenty/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts /Users/felixmalfait/Projects/twenty/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts: Unexpected token (71:19)

  69 |     icon: 'IconBuildingSkyscraper',
  70 |   })
> 71 |   [NAME_FIELD_NAME]: string;
     |                    ^
  72 |
  73 |   @WorkspaceField({
  74 |     standardId: COMPANY_STANDARD_FIELD_IDS.domainName,
SyntaxError: /Users/felixmalfait/Projects/twenty/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts: Unexpected token (71:19)

@timofei-iatsenko
Copy link
Collaborator

Most likely it's a syntax not supported by the babel version used in the extractor. Probably version bump for babel/* deps should resolve the issue.

I think what makes this syntax special is a combination of [] and decorator. Is it even a valid es syntax? For me this dynamic property access syntax belongs to the decorator itself not to the class, eq:

@myDecorator()['propertyOfDecorator']

@timofei-iatsenko
Copy link
Collaborator

Just checked babel repl, it seems that syntax was allowed in the 2023-11 version of decorators spec which was shipped somewhere in the 7.24.x babel version.

The lingui is defining constraint for the babel as ^7.21.0 it means it allows installing any newer version. So you should be able to install newer version without any issue (at least lingui wouldn't be the problem)

Update babel with yarn:

yarn up -r "@babel/*"

@timofei-iatsenko
Copy link
Collaborator

Checked your lock file, it seems you're using bebel/core@7.25.2 which should support this spec. Perhaps some additional changes to the babel parser options should be done on the lingui side. I'll investigate

@timofei-iatsenko
Copy link
Collaborator

@andrii-bodnar
Copy link
Contributor

Hi @FelixMalfait, congratulations on the successful integration of Lingui into Twenty! 🎉

Would you mind if we put Twenty's logo on the main page of the Lingui site?

@FelixMalfait
Copy link
Contributor Author

@andrii-bodnar hey no of course feel free to add it now, we'd be proud to be part of that list!

The frontend implementation is fairly simple and can be a good example for people who want to see a real-life implementation.
The backend is very specific to our CRM model where each customer has its own metadata so probably less people can relate to this. I still need to improve a lot of stuff (for example the compiled files are still commited), I think we'll release the multilingual version publicly by end of Feb.

@FelixMalfait
Copy link
Contributor Author

FelixMalfait commented Jan 28, 2025

https://github.com/twentyhq/twenty?tab=readme-ov-file#stack feel free to do a PR to add a link to Lingui there along Translation.io also (Lingui and Translation.io for translation).

I can do a PR to add our logo our your website but not today, most likely tomorrow

@andrii-bodnar
Copy link
Contributor

@FelixMalfait awesome, thank you! I will do both PRs :)

FelixMalfait pushed a commit to twentyhq/twenty that referenced this issue Jan 28, 2025
This PR adds Lingui to the translation tools in the Stack section of the
Readme, based on the suggestion in the comment
lingui/js-lingui#2159 (comment)
eliezer-rodrigues037 pushed a commit to mind-developer/kvoip-v2 that referenced this issue Jan 28, 2025
This PR adds Lingui to the translation tools in the Stack section of the
Readme, based on the suggestion in the comment
lingui/js-lingui#2159 (comment)
charlesBochet pushed a commit to twentyhq/twenty that referenced this issue Jan 28, 2025
This PR adds Lingui to the translation tools in the Stack section of the
Readme, based on the suggestion in the comment
lingui/js-lingui#2159 (comment)
eliezer-rodrigues037 pushed a commit to mind-developer/kvoip-v2 that referenced this issue Feb 15, 2025
This PR adds Lingui to the translation tools in the Stack section of the
Readme, based on the suggestion in the comment
lingui/js-lingui#2159 (comment)
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

4 participants