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

gt does not work on string literals #6

Open
blinry opened this issue Oct 24, 2023 · 3 comments
Open

gt does not work on string literals #6

blinry opened this issue Oct 24, 2023 · 3 comments

Comments

@blinry
Copy link

blinry commented Oct 24, 2023

We tried using a line like

gt("test")

in a TS file, and the jstsExtractor didn't catch it. We checked the code, and it seems that it currently only works on expressions like this:

gt({message: "test"})

Would it make sense to also allow gt to take plain strings? Thanks!

@blinry
Copy link
Author

blinry commented Oct 24, 2023

Oh! We learned that

gt`test`

works! What does this syntax mean?

@HenryLie
Copy link
Owner

Hey, thanks for trying out the lib!

I made gt syntax mostly the same as $t would in Svelte components, so it can accept either of these two forms:

  • plain string with tagged template literal syntax. In your example above: gt`test` is the right way to translate either plain strings or parameterized strings. This JS syntax behaves like calling the function called gt and passing in a parameterized string as its argument, so this is sort of equivalent of writing gt(`test`), just shorter 😁
  • the messageDescriptor syntax, which is like in your example gt({message: "test"}). This form is mostly only necessary if you'd like to add comments or context to the string extracted to the catalog, or if you'd like to use the plural form.

Let me know if you have any other question 😄

@blinry
Copy link
Author

blinry commented Oct 30, 2023

Makes sense! I'd suggest adding an example using gt`foo` to the README, so others will be less stumped than us! :D

Ohh, and that you can drop the parens is some some nice syntactic sugar, thanks for the explanation!

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