9
9
- ** Dynamic Language Support** : Add new languages by parsing PO files.
10
10
- ** Template Integration** : Works with Go HTML templates, extracting translation keys directly from them.
11
11
- ** Pluralization Support** : Handles singular and plural forms for languages with complex plural rules.
12
+ - ** Contextual Translations** : Supports context-based translations for more accurate localization.
12
13
- ** Prefix Handling** : Customizable prefix handling in translation keys, allowing for organized and readable translation files.
13
14
- ** Missing Translation Detection** : Scans for and logs missing translations, simplifying the translation management process.
14
15
@@ -47,6 +48,7 @@ func main() {
47
48
}
48
49
49
50
// add template functions
51
+ // this will add the tl, tn, ctl and ctn functions to the template
50
52
var yourTemplateFunctions = make (template.FuncMap )
51
53
for k , v := range tr.FuncMap () {
52
54
yourTemplateFunctions[k] = v
@@ -55,14 +57,14 @@ func main() {
55
57
56
58
Using the Translator in Templates
57
59
--
58
- Use tl for translating singular texts and tn for plural forms.
60
+ Use tl and ctl for translating singular texts and tn and ctn for plural forms.
59
61
60
62
` ` ` html
61
63
<!-- Singular -->
62
64
<p>{{ tl " Hello, World!" }}</p>
63
65
64
66
<!-- Plural -->
65
- <p>{{ tn " You have one message." " You have multiple messages." 5 }}</p>
67
+ <p>{{ tn " You have one message." " You have %d messages." 5 , 5 }}</p>
66
68
` ` `
67
69
Adding a New Language
68
70
--
@@ -101,7 +103,7 @@ translatedText := tr.Tl(localizer, "prefix__.your_translation_key") // output yo
101
103
TODO
102
104
--
103
105
- add caching functionality of the loaded translated keys.
104
- - add unit tests
106
+ - add more unit tests
105
107
- live reload translations when the file changes
106
108
- fallback language
107
109
0 commit comments