Joker / jade

Jade.go - pug template engine for Go (golang)
BSD 3-Clause "New" or "Revised" License
352 stars 36 forks source link

Filters - i18n #50

Closed UnrealView closed 1 year ago

UnrealView commented 1 year ago

First of all, thank you for your project!

After several tests, I am interested in the internationalization process and I'm currently stuck.

Based on pugjs doc, I thought that filters is an option to implement an i18n. But I can't find a way to implement my own filter. It seems that the test filters.jade doesn't work in terms of output. When I see the parseFilter function with a switch I assume is not built to be extended.

Is there another solution to my problem? Am I misusing the filters functions?

UnrealView commented 1 year ago

I finally found a cool solution and I share my idea here. Note, I build my own i18n system.

In this example, the var _i18n store the function permit to retrieve the value from the key:

- var _i18n = i18n.GetInstance().Get

//...

    p i18n test [error.NotFirstLaunch] - #{_i18n("error.NotFirstLaunch")}
    p i18n test [view.index.day, 10] - #{_i18n("view.index.day", 10)}
    p i18n test [view.index.day, 1] - #{_i18n("view.index.day", 1)}

Possible output:

i18n test [error.NotFirstLaunch] - This is not the first launch.
i18n test [view.index.day, 10] - 10 days left
i18n test [view.index.day, 1] - 1 day left