forked from chai2010/gettext-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2020 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package gettext | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
type jsonFS struct { | ||
name string | ||
x map[string]struct { | ||
LC_MESSAGES map[string][]struct { | ||
MsgContext string `json:"msgctxt"` // msgctxt context | ||
MsgId string `json:"msgid"` // msgid untranslated-string | ||
MsgIdPlural string `json:"msgid_plural"` // msgid_plural untranslated-string-plural | ||
MsgStr []string `json:"msgstr"` // msgstr translated-string | ||
} | ||
LC_RESOURCE map[string]map[string]string | ||
} | ||
} | ||
|
||
func isJsonData() bool { | ||
return false | ||
} | ||
|
||
func newJson(jsonData []byte, name string) (*jsonFS, error) { | ||
p := &jsonFS{name: name} | ||
if err := json.Unmarshal(jsonData, &p.x); err != nil { | ||
return nil, err | ||
} | ||
|
||
return p, nil | ||
} | ||
|
||
func (p *jsonFS) LocaleList() []string { | ||
var ss []string | ||
for lang := range p.x { | ||
ss = append(ss, lang) | ||
} | ||
sort.Strings(ss) | ||
return ss | ||
} | ||
|
||
func (p *jsonFS) LoadMessagesFile(domain, lang, ext string) ([]byte, error) { | ||
if v, ok := p.x[lang]; ok { | ||
if v, ok := v.LC_MESSAGES[domain+ext]; ok { | ||
return json.Marshal(v) | ||
} | ||
} | ||
return nil, fmt.Errorf("not found") | ||
} | ||
func (p *jsonFS) LoadResourceFile(domain, lang, name string) ([]byte, error) { | ||
if v, ok := p.x[lang]; ok { | ||
if v, ok := v.LC_RESOURCE[domain]; ok { | ||
return []byte(v[name]), nil | ||
} | ||
} | ||
return nil, fmt.Errorf("not found") | ||
} | ||
func (p *jsonFS) String() string { | ||
return "gettext.nilfs(" + p.name + ")" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters