trl

package
v0.0.0-...-fe173bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package trl is a central store for application environment translations; While specific objects such as QuestionnaireT contain translations for its contents, we need some global store too.

Index

Constants

This section is empty.

Variables

View Source
var Countries = map[string]S{}/* 219 elements not displayed */

Countries is contains translations of country names by ISO code

View Source
var CountryISOs = []string{}

CountryISOs provides some stable default sorting

View Source
var FederalStatesGermany = map[string]S{
	"BW": {"de": "Baden-Württemberg"},
	"BY": {"de": "Bayern"},
	"BE": {"de": "Berlin"},
	"BB": {"de": "Brandenburg"},
	"HB": {"de": "Bremen"},
	"HH": {"de": "Hamburg"},
	"HE": {"de": "Hessen"},
	"NI": {"de": "Niedersachsen"},
	"MV": {"de": "Mecklenburg-Vorpommern"},
	"NW": {"de": "Nordrhein-Westfalen"},
	"RP": {"de": "Rheinland-Pfalz"},
	"SL": {"de": "Saarland"},
	"SN": {"de": "Sachsen"},
	"ST": {"de": "Sachsen-Anhalt"},
	"SH": {"de": "Schleswig-Holstein"},
	"TH": {"de": "Thüringen"},
}

FederalStatesGermany for multiple questionnaires

View Source
var FederalStatesGermanyISOs = []string{}

FederalStatesGermanyISOs - sorted by ISO code

View Source
var FederalStatesGermanyISOs2 = sorterDeSl{}

FederalStatesGermanyISOs2 - sorted by German label

View Source
var LangCodes = []string{"de", "en"}

LangCodes for returning multiple translations. When no langCode is available, then the first entry rules. A call to All() returns explicitly all key-values. LangCodes will be initialized in cfg.Load().LangCodes; we prevent circular dependency

Functions

func EnglishMonths

func EnglishMonths() []string

func HyphenizeText

func HyphenizeText(s string) string

HyphenizeText replaces "mittelfristig" with "mittel|fristig" Hyphenization is done _once_ during creation of the questionare JSON template.

We replace longer keys first, to prevent erratic results for example from

desa|cuer|do

func MonthsShift

func MonthsShift(i, shift int) int

MonthsShift could use date.Add - but it would be wasteful

Types

type Map

type Map map[string]S

Map - Translations Type Usage in templates

{{.Trls.imprint.en                     }}  // directly accessing a specific translation; chaining the map keys
{{.Trls.imprint.Tr       .Sess.LangCode}}  // using .Tr(langCode)
{{.Trls.imprint.TrSilent .Sess.LangCode}}  //

func CoreTranslations

func CoreTranslations() Map

CoreTranslations returns a core of transations, to be extended or overwritten by application config data. To reference app translations in questionnaires, use cfg.Get().Mp[key]

type MapSite

type MapSite map[string]Map

MapSite for sub-site specific translations

type S

type S map[string]string

S stores a multi lingual string. Contains one value for each language code.

func MonthByInt

func MonthByInt(i int) S

MonthByInt maps 1 to January, 12 to December

func (S) All

func (s S) All(args ...string) string

All returns all translations with their % placeholders filled in by param args; ordered by lang codes separated by '\n\n'

func (S) Append

func (s S) Append(sfx S) S

func (S) Append90

func (s S) Append90(sfx S) S

Append90 - indented new line and 90 percent font-size

func (S) AppendStr

func (s S) AppendStr(sfx string) S

AppendStr - single string to all keys

func (S) Bold

func (s S) Bold() S

Bold encloses in <b> ... </b>

func (S) Empty

func (s S) Empty() bool

Empty checks whether s has only empty translations; trl.S{} creates one;

func (S) Fill

func (s S) Fill(args ...interface{}) S

Fill fills in the %v placeholders; S is a map - thus always a pointer thus we dont change the receiver, but return a clone

func (S) Left

func (s S) Left(max int) S

Left trims

func (S) Outline

func (s S) Outline(pref string) S

Outline prepends <b> pref </b>

func (S) OutlineHid

func (s S) OutlineHid(pref string) S

OutlineHid prepends pref as comment - invisible

func (S) Pad

func (s S) Pad(spaces int) S

Pad with &nbsp;

func (S) RemoveSomeHTML

func (s S) RemoveSomeHTML() S

RemoveSomeHTML removes <span *>, </span>, <b>, </b>, &nbsp; .

func (S) Set

func (s S) Set() bool

Set checks whether s is nil or has no keys

func (S) Size

func (s S) Size() float64

Size returns *average* length of text; this is expensive; only for static stuff

func (S) String

func (s S) String() string

String is the default "stringer" implementation Similar to Tr() - except third try: take whatever exists

func (S) Tr

func (s S) Tr(langCode string) string

Tr translates by key. Defaults to english. Defaults otherwise to first lang code. Returns a 'signifiers string' if no translation exists, to help to uncover missing translations.

func (S) TrSilent

func (s S) TrSilent(langCode string) string

TrSilent gives no warning - if the translation is not set. Good if we do not require a translation string. Good for i.e. HTML title attribute - where errors would be overlooked anyway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL