add TranslateStringLocalizer() and improve core.go documentation
This commit is contained in:
+11
-1
@@ -100,6 +100,7 @@ func Init(dataPath string, localizer *localizations.Localizer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteJSON writes a FullData to disk
|
||||||
func (d *FullData) WriteJSON(dataPath string) error {
|
func (d *FullData) WriteJSON(dataPath string) error {
|
||||||
// use .new so if there's a corruption when writing the old file is intact
|
// use .new so if there's a corruption when writing the old file is intact
|
||||||
path := filepath.Join(dataPath, "comitium.json.new")
|
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
|
// replace everything using the localizer replacements, and then substitute that
|
||||||
// string into the template string.
|
// string into the template string.
|
||||||
func TranslateString(template, localizerTag string, replacements *localizations.Replacements) 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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user