@@ -21,30 +21,29 @@ multiple languages at the same time by working with this object.
21
21
22
22
Example:
23
23
24
- import (
25
- "encoding/gob"
26
- "bytes"
27
- "fmt"
28
- "github.com/leonelquinteros/gotext"
29
- )
24
+ import (
25
+ "encoding/gob"
26
+ "bytes"
27
+ "fmt"
28
+ "github.com/leonelquinteros/gotext"
29
+ )
30
30
31
- func main() {
32
- // Create Locale with library path and language code
33
- l := gotext.NewLocale("/path/to/i18n/dir", "en_US")
31
+ func main() {
32
+ // Create Locale with library path and language code
33
+ l := gotext.NewLocale("/path/to/i18n/dir", "en_US")
34
34
35
- // Load domain '/path/to/i18n/dir/en_US/LC_MESSAGES/default.{po,mo}'
36
- l.AddDomain("default")
35
+ // Load domain '/path/to/i18n/dir/en_US/LC_MESSAGES/default.{po,mo}'
36
+ l.AddDomain("default")
37
37
38
- // Translate text from default domain
39
- fmt.Println(l.Get("Translate this"))
38
+ // Translate text from default domain
39
+ fmt.Println(l.Get("Translate this"))
40
40
41
- // Load different domain ('/path/to/i18n/dir/en_US/LC_MESSAGES/extras.{po,mo}')
42
- l.AddDomain("extras")
43
-
44
- // Translate text from domain
45
- fmt.Println(l.GetD("extras", "Translate this"))
46
- }
41
+ // Load different domain ('/path/to/i18n/dir/en_US/LC_MESSAGES/extras.{po,mo}')
42
+ l.AddDomain("extras")
47
43
44
+ // Translate text from domain
45
+ fmt.Println(l.GetD("extras", "Translate this"))
46
+ }
48
47
*/
49
48
type Locale struct {
50
49
// Path to locale files.
@@ -83,6 +82,14 @@ func NewLocaleFS(l string, filesystem fs.FS) *Locale {
83
82
return loc
84
83
}
85
84
85
+ // NewLocaleFSWithPath returns a Locale working with a fs.FS on a p path folder.
86
+ func NewLocaleFSWithPath (l string , filesystem fs.FS , p string ) * Locale {
87
+ loc := NewLocale ("" , l )
88
+ loc .fs = filesystem
89
+ loc .path = p
90
+ return loc
91
+ }
92
+
86
93
func (l * Locale ) findExt (dom , ext string ) string {
87
94
filename := path .Join (l .path , l .lang , "LC_MESSAGES" , dom + "." + ext )
88
95
if l .fileExists (filename ) {
@@ -333,7 +340,7 @@ func (l *Locale) GetNDC(dom, str, plural string, n int, ctx string, vars ...inte
333
340
return Printf (plural , vars ... )
334
341
}
335
342
336
- //GetTranslations returns a copy of all translations in all domains of this locale. It does not support contexts.
343
+ // GetTranslations returns a copy of all translations in all domains of this locale. It does not support contexts.
337
344
func (l * Locale ) GetTranslations () map [string ]* Translation {
338
345
all := make (map [string ]* Translation )
339
346
0 commit comments