marhali / easy-i18n

This is a IntelliJ IDE based plugin for internationalization. Supports the most common translation file types.
MIT License
82 stars 26 forks source link

support display translation keys with obj notation #382

Open Solexofficial opened 8 months ago

Solexofficial commented 8 months ago

Hello Marcel!👋 Can you make an improvement so that the display of the translation key is available not only for strings, like "key" but is also displayed when accessing an object (a certain pattern), for example {i18n.key}. By analogy, when replacement occurs when calling the function {{t('key')}} other plugins, but specifically for objects. file.tsx

Screenshot 2024-03-22 at 15 25 34

How difficult is it to implement?

marhali commented 7 months ago

Is this related to https://github.com/marhali/easy-i18n/pull/345?

Solexofficial commented 7 months ago

is very similar! but there is work with strings. with notation like i18n.key is not supported (

Solexofficial commented 7 months ago

@JPilson can you please look at this? ☝️

JPilson commented 7 months ago

@Solexofficial I'm not sure if I understood correct but you want to be able to access the key from an object, so that you have some sort of type safe with keys?

 const  translated  = t('key')

but also

import i18n from '...'
...
 const translated = t(i18n.key)

Is this what you want ?

Solexofficial commented 7 months ago

It is very necessary that the translation be displayed when accessing the object key.🙏

en.json
{
  "continue_key": "Continue"
}
export const i18n = {
  continue_key: "Continue"
}
import i18n from '..'

const Component = () => {
  return <button>{i18n.continue_key}</button>
 }

was displayed as

import i18n from '..'

const Component = () => {
  return <button>{'Continue'}</button>
 }
JPilson commented 7 months ago

I see, If get time I can look into it. I'm not promising anything and its not related to https://github.com/marhali/easy-i18n/pull/345

Solexofficial commented 6 months ago

Unfortunately, https://github.com/marhali/easy-i18n/pull/345 we are talking about replacement in strings, but I ask you to add the ability to replace not only strings (Literal), but also objects (Member Expression). https://astexplorer.net/#/gist/3c971281dcfa5fb6015222bf3fed8cf8/b5bdf3d7301042ae1c9fea3f3c1cfc4ce892ea59 {i18n.continue} display like {Continue} This will be very useful for most developers. Thank you!

Solexofficial commented 1 month ago

up