lang

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 14 Imported by: 6

README

godoc Go Report Card

lang - text language utilities

A collection of common functions and catalog constructs for text language processing.

Note that there is no documentation and these utilities are intended for the needs of the go-enjin/be and enjenv projects at this time.

Installation

> go get github.com/go-corelibs/lang@latest

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2024 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package lang provides text language utilities

Index

Constants

This section is empty.

Variables

View Source
var (
	// TranslationCommandName is the name of the text and html template
	// FuncMap entry responsible for rendering translated text. The named
	// function must support a [fmt.Sprintf]-like call signature
	//
	// By default, the TranslationCommandName is set to the Go-Enjin standard
	// translation function (which is just a single underscore)
	TranslationCommandName = "_"

	// TrimLayoutsFromFilename determines whether ParseTemplateTranslations
	// will remove the `.../layouts/` parent paths from the filename
	TrimLayoutsFromFilename = true
)

Functions

func CoalesceTranslatorComment

func CoalesceTranslatorComment(input string) (coalesced string)

func ParsePluralCaseKey

func ParsePluralCaseKey(key string) (real string)

func ParseTag

func ParseTag(input interface{}) (tag language.Tag, err error)

func ParseTranslatorComment

func ParseTranslatorComment(input string) (comments, sources []string)

func Prune added in v0.3.0

func Prune(input, characters string) string

Prune removes all characters from input

TODO: move Prune to github.com/go-corelibs/strings

func PruneTranslatorComments deprecated

func PruneTranslatorComments(input string) (clean string)

Deprecated: PruneTranslatorComments is now a simple wrapper around the generically useful and optimized: github.com/go-corelibs/tmplstr.RemoveTemplateComments

func SortLanguageTags

func SortLanguageTags(tags []language.Tag) (sorted []language.Tag)

func SortedLanguageTagKeys

func SortedLanguageTagKeys[V interface{}](m map[language.Tag]V) (sorted []language.Tag)

func TagInTagSlices

func TagInTagSlices(needle language.Tag, haystacks ...[]language.Tag) (found bool)

func TagInTags

func TagInTags(needle language.Tag, haystack ...language.Tag) (found bool)

Types

type BaseMessage

type BaseMessage struct {
	ID                string       `json:"id"`
	Key               string       `json:"key"`
	Message           string       `json:"message"`
	Translation       interface{}  `json:"translation"`
	TranslatorComment string       `json:"translatorComment,omitempty"`
	Placeholders      Placeholders `json:"placeholders,omitempty"`
	Fuzzy             bool         `json:"fuzzy,omitempty"`
}

type GoText

type GoText struct {
	Language string   `json:"language"`
	Messages Messages `json:"messages"`
}

func ParseGoText

func ParseGoText(data []byte) (gt *GoText, tag language.Tag, err error)

func (*GoText) Sort added in v0.3.0

func (g *GoText) Sort()

type Message

type Message struct {
	ID                string       `json:"id"`
	Key               string       `json:"key"`
	Message           string       `json:"message"`
	Translation       *Translation `json:"translation"`
	TranslatorComment string       `json:"translatorComment,omitempty"`
	Placeholders      Placeholders `json:"placeholders,omitempty"`
	Fuzzy             bool         `json:"fuzzy,omitempty"`
}

func MakeMessageFromKey

func MakeMessageFromKey(key, comment string, argv ...string) (m *Message)

func ParseTemplateTranslations added in v0.3.0

func ParseTemplateTranslations(filename, source string) (msgs []*Message, err error)

ParseTemplateTranslations uses github.com/go-corelibs/tmplstr ParseTemplate and searches for any actions calling TranslationCommandName, parsing the message ID, arguments and comments into a Message structure

func (*Message) Copy

func (m *Message) Copy() (copied *Message)

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() (data []byte, err error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) (err error)

type Messages added in v0.3.0

type Messages []*Message

func (Messages) Sort added in v0.3.0

func (m Messages) Sort()

type Placeholder

type Placeholder struct {
	ID             string `json:"id"`
	String         string `json:"string"`
	Type           string `json:"type"`
	UnderlyingType string `json:"underlyingType"`
	ArgNum         int    `json:"argNum"`
	Expr           string `json:"expr"`
}

type Placeholders

type Placeholders []*Placeholder

func ParseMessagePlaceholders

func ParseMessagePlaceholders(key string, argv ...string) (replaced, labelled string, placeholders Placeholders)

func (Placeholders) Copy

func (p Placeholders) Copy() (copied Placeholders)

func (Placeholders) Numeric

func (p Placeholders) Numeric() (found Placeholders)

type Select

type Select struct {
	Arg     string                `json:"arg"`
	Feature string                `json:"feature"`
	Cases   map[string]SelectCase `json:"cases"`
}

type SelectCase

type SelectCase struct {
	Msg string `json:"msg"`
}

type SelectMessage

type SelectMessage struct {
	ID                string       `json:"id"`
	Key               string       `json:"key"`
	Message           string       `json:"message"`
	Translation       *Translation `json:"translation"`
	TranslatorComment string       `json:"translatorComment,omitempty"`
	Placeholders      Placeholders `json:"placeholders,omitempty"`
	Fuzzy             bool         `json:"fuzzy,omitempty"`
}

func (*SelectMessage) Make

func (s *SelectMessage) Make() (m Message)

type StringMessage

type StringMessage struct {
	ID                string       `json:"id"`
	Key               string       `json:"key"`
	Message           string       `json:"message"`
	Translation       string       `json:"translation"`
	TranslatorComment string       `json:"translatorComment,omitempty"`
	Placeholders      Placeholders `json:"placeholders,omitempty"`
	Fuzzy             bool         `json:"fuzzy,omitempty"`
}

func (*StringMessage) Make

func (s *StringMessage) Make() (m Message)

type Tags

type Tags []language.Tag

func (Tags) Has

func (list Tags) Has(tag language.Tag) (present bool)

func (Tags) Strings

func (list Tags) Strings() (locales []string)

func (Tags) StringsWithDefault

func (list Tags) StringsWithDefault(tag language.Tag) (locales []string)

type Translation

type Translation struct {
	String string  `json:"string,omitempty"`
	Select *Select `json:"select,omitempty"`
}

Jump to

Keyboard shortcuts

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