summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-05-11 15:17:08 -0600
committernytpu <alex@nytpu.com>2021-05-11 15:17:08 -0600
commitd369236fadaec6f6eb25a586291f4a9f5b5d42dd (patch)
tree329ebbca1bd2cfcf0eb3da25d6991992dde2dfc9 /core
parent6e1fc209cce9904003ca4eee3c9e09c81ddeb250 (diff)
add TranslateStringLocalizer() and improve core.go documentation
Diffstat (limited to 'core')
-rw-r--r--core/core.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/core.go b/core/core.go
index b5acf46..5f1e86e 100644
--- a/core/core.go
+++ b/core/core.go
@@ -100,6 +100,7 @@ func Init(dataPath string, localizer *localizations.Localizer) error {
return nil
}
+// WriteJSON writes a FullData to disk
func (d *FullData) WriteJSON(dataPath string) error {
// use .new so if there's a corruption when writing the old file is intact
path := filepath.Join(dataPath, "comitium.json.new")
@@ -125,5 +126,14 @@ func (d *FullData) WriteJSON(dataPath string) error {
// replace everything using the localizer replacements, and then substitute that
// string into the template string.
func TranslateString(template, localizerTag string, replacements *localizations.Replacements) string {
- return fmt.Sprintf(template, Localizer.Get(localizerTag, replacements))
+ return TranslateStringLocalizer(Localizer, template, localizerTag, replacements)
+}
+
+// TranslateStringLocalizer takes a localizations.Localizer, template string, a
+// localizer tag, and a localizer replacement set and will get the localized
+// string from the localizer tag, replace everything using the localizer
+// replacements, and then substitute that string into the template string.
+// Should not be used once core.Init() is called, instead use TranslateString().
+func TranslateStringLocalizer(localizer *localizations.Localizer, template, localizerTag string, replacements *localizations.Replacements) string {
+ return fmt.Sprintf(template, localizer.Get(localizerTag, replacements))
}