Create MO parser
Refactored a bit too, so we can use interfaces to take Mo and Po files added fixtures found that the parser for Po files have a bug... but it works... so not touched
This commit is contained in:
48
translation.go
Normal file
48
translation.go
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2018 DeineAgentur UG https://www.deineagentur.com. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
*/
|
||||
|
||||
package gotext
|
||||
|
||||
type Translation struct {
|
||||
ID string
|
||||
PluralID string
|
||||
Trs map[int]string
|
||||
}
|
||||
|
||||
func NewTranslation() *Translation {
|
||||
tr := new(Translation)
|
||||
tr.Trs = make(map[int]string)
|
||||
|
||||
return tr
|
||||
}
|
||||
|
||||
func (t *Translation) Get() string {
|
||||
// Look for Translation index 0
|
||||
if _, ok := t.Trs[0]; ok {
|
||||
if t.Trs[0] != "" {
|
||||
return t.Trs[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Return untranslated id by default
|
||||
return t.ID
|
||||
}
|
||||
|
||||
func (t *Translation) GetN(n int) string {
|
||||
// Look for Translation index
|
||||
if _, ok := t.Trs[n]; ok {
|
||||
if t.Trs[n] != "" {
|
||||
return t.Trs[n]
|
||||
}
|
||||
}
|
||||
|
||||
// Return untranslated singular if corresponding
|
||||
if n == 0 {
|
||||
return t.ID
|
||||
}
|
||||
|
||||
// Return untranslated plural by default
|
||||
return t.PluralID
|
||||
}
|
||||
Reference in New Issue
Block a user