-
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.
Moved default & supported langs into the storage
This changes the way a router is created, but it also means that supported/default languages are synced for all routers using a storage.
- Loading branch information
Adam Talbot
committed
Dec 20, 2015
1 parent
9c03164
commit f88521a
Showing
13 changed files
with
616 additions
and
92 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
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,33 @@ | ||
package redis | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/ThatsMrTalbot/i18n" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
type translationObject struct { | ||
Lang string `json:"lang"` | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func encode(t *i18n.Translation) string { | ||
data, _ := json.Marshal(&translationObject{ | ||
Lang: t.Lang.String(), | ||
Key: t.Key, | ||
Value: t.Value, | ||
}) | ||
return string(data) | ||
} | ||
|
||
func decode(t string) (*i18n.Translation, error) { | ||
var obj translationObject | ||
err := json.Unmarshal([]byte(t), &obj) | ||
return &i18n.Translation{ | ||
Lang: language.Make(obj.Lang), | ||
Key: obj.Key, | ||
Value: obj.Value, | ||
}, err | ||
} |
Oops, something went wrong.