Skip to content

should variables apply when defaultMessage is used? #8

Open

Description

@ArsSirek

Hi,
Not sure if it is a bug, but with my usage of extract-intl, I had a case, when the locale message was actually an empty string, so we passed this null check variables had no effect, and the defaultMessage is shown in the end with {variable} as in "locale.json".

I don't know what is a right thing to do, but it seems to me that the desired result would be to have variables inserted into defaultMessage as well.

Thanks!

Activity

  1. cwtuan commented on Jul 2, 2017

    @cwtuan
    Collaborator

    Could you show the detail of this case? How do you use defaultMessage method?

  2. ArsSirek commented on Jul 2, 2017

    @ArsSirek
    Author

    Hi, I wrote an example showing my usage, wasn't sure how to provide it, so I forked and added it here in examples folder #10

    And there is a branch on that fork, that shows a problem I mentioned in this issue
    to reproduce you can,

    • switch to that branch, npm i
    • npm run extract-intl (that will add an gb.json to locales folder with empty strings as there is no translation yet)
    • npm run start
      now when you choose gb as locale, the messages with variables remain as they are in file, despite that we have all it needs to place the variables
      Hope that helps, best of luck!
  3. Panoplos commented on Apr 22, 2018

    @Panoplos

    Actually, variables are ignored in the case of using intl.get('something', {foo}).d('something {foo} bar'), so this seems like a bug, as this call results in 'something {foo} bar'. Kind of meaningless to have defaults if this is the case.

  4. cwtuan commented on Apr 24, 2018

    @cwtuan
    Collaborator

    @Panoplos
    It should be intl.get('something', {foo}).d(`something ${foo} bar`)

  5. Panoplos commented on Apr 26, 2018

    @Panoplos

    The documentation doesn't mention this.

    screen shot 2018-04-26 at 12 11 41

  6. Panoplos commented on Apr 26, 2018

    @Panoplos

    Or rather, it does in the API section, but why is the default variable tag spec different from the locale data?

    We have a script that automatically scrapes out defaults to build the base locale, having these be different requires us to remove the $.

  7. cwtuan commented on Apr 27, 2018

    @cwtuan
    Collaborator

    @Panoplos
    The defaultMesssage is now ES6 Template literals format. And the locale file is ICU format.

    I will make this intl.get('something', {foo}).d('something {foo} bar') work, too, in next release.
    Thanks for the suggestion.

  8. liuyiliuyi commented on Mar 7, 2022

    @liuyiliuyi

    @cwtuan Hi, is there any progress.

  9. cwtuan commented on Mar 9, 2022

    @cwtuan
    Collaborator

    @liuyiliuyi
    After reconsideration, I'd like to remain the current behavior for this API, because this proposal may make break changes.

    And you could use react-intl-universal-extract
    to extract the text in source code to locale files. It will remove the $ automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions