nicksnyder / go-i18n

Translate your Go program into multiple languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting the delimiters globally?

lucijaff opened this issue · comments

Is there a way to set the delimiters globally for the entire bundle?

I'm storing messages in JSON files and would like to replace default {{ and }} delimiters with something else, on the project level. I can't find any examples that would cover this.

If this is not possible, would you mind sharing an example using custom delimiters for a single message, but used when messages are stored as JSON files and not hardcoded in e.g. a go controller? I can't figure out from the examples with custom delimiters where the translated messages come into play.

Unfortunately delimiters can only be set per message right now.

This is an example of how to do this in code: https://sourcegraph.com/github.com/nicksnyder/go-i18n/-/blob/v2/i18n/example_test.go?L126

But you should also be able to specific this per message in the json file like this

{
    "hellomessage": {
        "other": "Hello <<.Name>>",
        "leftdelim": "<<",
        "rightdelim": ">>",
    }
}

I think the original reason I didn't add the option to set this on the bundle, or more globally, is because the current structure of the file format doesn't make it easy to add file level config (the top level is messages), and if you just put this config in code then the message files are not portable. Message files not being portable is probably not a big deal, so it seems like it could be fine to add an option to support this on the bundle.

I am curious, what is your use case for using different delimiters? Are you interested to contribute a PR?

@nicksnyder thanks for the quick response! The JSON example should work for what I need.

In my case, I would like to use different delimiters because I'm using the strings in a templating engine that also uses {{ and }} as tag delimiters, so at times, there's a clash. But since the problem is not global, setting them per message where needed will work great.