Documentation
¶
Overview ¶
Package language is subflux's language model: canonical BCP 47 tags over langtag, the subtitle targets a configuration asks for, how close an offered tag is to a target and whether automation may take it, and the filename spellings subflux writes and reads.
Parse is the one canonicalizer. ReadFilename is the one filename reader; its exception table is read by nothing else, so a spelling it accepts never becomes a configured target. Every function computes and returns; none logs.
Index ¶
- Constants
- func EnglishName(t Tag) string
- func FilenameTag(t Tag) string
- func ISO3(t Tag) (string, bool)
- type Class
- type CloseName
- type Closeness
- type Flags
- type Grade
- type Name
- type Policy
- func (p Policy) AutoQuery(needing, offered []Tag) []Tag
- func (p Policy) Automatic(g Grade) bool
- func (p Policy) CloseVarieties() bool
- func (p Policy) Digest() [32]byte
- func (Policy) Grade(target, have Tag) Grade
- func (p Policy) ManualQuery(target Tag, offered []Tag) []Tag
- func (p Policy) Targets() []Target
- func (p Policy) TargetsFor(original Tag, audio []Tag) []Target
- type ProviderMap
- type Tag
- type Target
- type Variant
- type WirePair
Constants ¶
const FormatVersion uint16 = 1
FormatVersion changes with any tag's canonical text: a langtag or x/text bump that respells one, a fold rule, a language entering or leaving MultiScript. Storage folds it into every tag-holding codec version, so a bump resets core state; testdata/format-v<N>.golden pins version N.
Variables ¶
This section is empty.
Functions ¶
func EnglishName ¶
EnglishName is the English name of any tag ("Portuguese (Brazil)"), its canonical text when langtag names none, "" for the zero Tag.
func FilenameTag ¶
FilenameTag is the language segment subflux writes into a subtitle file name: "" for the zero Tag, zh-CN, zh-TW and zh-HK for zh-Hans, zh-Hant and zh-Hant-HK (the region forms media servers read), and the canonical text of every other tag, at most 12 bytes of [A-Za-z0-9-].
Types ¶
type Class ¶
type Class uint8
Class is what subflux may do with an offered tag for a target. Zero is invalid.
The classes: Exact and Substitute may be automatic (Policy.Automatic), ManualOnly is listed for a person to pick, Unrelated is never listed.
func (Class) MarshalText ¶
MarshalText is exact, substitute, manual_only or unrelated.
func (*Class) UnmarshalText ¶
UnmarshalText refuses every spelling but MarshalText's.
type Closeness ¶
type Closeness uint8
Closeness is how far an offered tag sits from a target, nearest first. Zero is invalid.
The closenesses. OtherScript sits after Intelligible because automation never crosses scripts, whatever langtag's tier order says.
func (Closeness) MarshalText ¶
MarshalText is identical, same_language, other_region, intelligible, other_script or unrelated.
func (*Closeness) UnmarshalText ¶
UnmarshalText refuses every spelling but MarshalText's.
type Flags ¶
type Flags struct{ HI, Forced bool }
Flags is what a file, track or candidate carries; all four combinations are valid.
func ReadFlags ¶
ReadFlags is what free texts (a release or file name, a provider's comment, a track title) say of a subtitle's flags. A flag is set when one text names it and none denies it, so the order of texts never matters. A word is a run of letters and digits matched whole, so "Foreigner", "Reinforced" and "Hi10p" name nothing. The Title-case word "Hi" is the greeting ("Hi-Score", "Oh.Hi.Mark") and names nothing, though a denial with it ("Non-Hi") still denies, while "HI" and "hi" name HI.
type Grade ¶
Grade is one target's judgement of one offered tag; Reason is one English line describing it.
type Name ¶
Name is one tag a person can pick as a target, with its English name and the other pickable tags it grades Exact, Substitute or ManualOnly.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy is the parsed languages section: the targets each item wants and the close-varieties switch. It is immutable; the zero Policy has no targets, the switch off and a fixed digest.
func ParsePolicy ¶
func ParsePolicy(n *yaml.Node) (Policy, []formschema.FieldError)
ParsePolicy reads the languages section, n being its value node (nil when the section is absent), and returns every field error at once, each path absolute from the config root (languages.rules[1].targets[0].tag). On any error the Policy is the zero Policy. Every scalar is read by its text whatever its YAML tag, except that one tagged !!null is absent (formschema.IsNull), so an explicit !!str ~ is a string. Afterwards, valid or not, every scalar under n is marked formschema.PlainTag: the section holds no secret.
func (Policy) AutoQuery ¶
AutoQuery is the offered tags a provider is asked for automatically: each offered tag Automatic for some target in needing, once, ordered by the position in needing of the first target it serves, then its closeness to that target, then offered order. It never returns a ManualOnly tag.
func (Policy) Automatic ¶
Automatic reports whether a grade lets subflux take the offer without a person: Exact always, Substitute while close varieties are on.
func (Policy) CloseVarieties ¶
CloseVarieties reports the close-varieties switch: while on, a Substitute grade is automatic.
func (Policy) Digest ¶
Digest is a SHA-256 of the section as configured (the switch, every list, tag and variant, in order), so equal sections share it and any change moves it. It names the section only, never the grading code.
func (Policy) Grade ¶
Grade judges have as an offer for target: how close it is and whether it may serve automatically, ignoring the close-varieties switch (Automatic applies it). Either tag zero grades Unrelated.
func (Policy) ManualQuery ¶
ManualQuery is the offered tags a person may pick for target, whatever the close-varieties switch: each graded Exact, Substitute or ManualOnly, once, ordered by class, then closeness, then offered order.
func (Policy) Targets ¶
Targets is every configured target once, the defaults first then each rule's in order, a tag's variants the union of its listings in Variant order. The answer is the caller's to change.
func (Policy) TargetsFor ¶
TargetsFor answers the targets of an item: the closest-tier rule matching original, ties by config order, then each audio track the same way, else the default targets. A matched rule with no targets stops the chain, so the item wants nothing. The answer is the caller's to change.
type ProviderMap ¶
type ProviderMap struct {
// contains filtered or unexported fields
}
ProviderMap is one provider's two-way table between its language labels and tags. Lookups are exact: normalizing a label is the adapter's job. The zero ProviderMap is empty.
func MustProviderMap ¶
func MustProviderMap(pairs []WirePair) ProviderMap
MustProviderMap is NewProviderMap for package-level adapter tables; it panics on NewProviderMap's error.
func NewProviderMap ¶
func NewProviderMap(pairs []WirePair) (ProviderMap, error)
NewProviderMap builds a map from pairs, refusing an empty, over-64-byte or invalid UTF-8 label, a zero tag, and a label listed twice; the error names the first bad pair. A tag may carry several labels, kept in pair order.
func (ProviderMap) Tag ¶
func (m ProviderMap) Tag(wire string) (Tag, bool)
Tag is the tag the provider means by wire.
func (ProviderMap) Tags ¶
func (m ProviderMap) Tags() []Tag
Tags is every mapped tag once, in first-pair order, in a slice the caller owns.
func (ProviderMap) Wires ¶
func (m ProviderMap) Wires(t Tag) []string
Wires is every label the provider files t under, in pair order, in a slice the caller owns; nil when t is not mapped.
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag is a canonical BCP 47 language tag, folded to its representative: Parse and every reader built on it fold zh-CN to zh-Hans, zh-TW to zh-Hant and zh-HK to zh-Hant-HK, the inverse of FilenameTag, and a region implying its script states it (ku-IQ to ku-Arab-IQ). == is canonical equality; the zero Tag means no language.
func FromName ¶
FromName reads a language as an English name (CLDR's, a pickable tag's composed name, or Sonarr's and Radarr's, in any ASCII case) or, failing that, as a code Parse reads. It answers false for empty input, input over 64 bytes after trimming, and the arr values Unknown, Any and Original.
func Parse ¶
Parse canonicalizes raw (ISO 639-1, 639-2, 639-3 or BCP 47, any ASCII case) and folds it to its representative. "" is the zero Tag and true; any other input naming no language is the zero Tag and false. Parse reads no filename exception: ReadFilename does.
func ReadFilename ¶
ReadFilename reads one language segment of a subtitle file name: a spelling other tools commonly write (pb, cht, es-la, in any ASCII case) reads as the tag it means there, and anything else as Parse reads it. "" is the zero Tag and true.
func RefineFromTitle ¶
RefineFromTitle adds to t what an embedded track's title states and t lacks: a script for a Chinese, Cantonese or Serbian tag stating none, a region for a Portuguese, Spanish or French tag stating none. A title naming two results refines nothing, and the language never changes. Bounding the title is the caller's.
func (Tag) MarshalText ¶
MarshalText is the canonical text, empty for the zero Tag.
func (*Tag) UnmarshalText ¶
UnmarshalText decodes wire and config input strictly: empty text is the zero Tag, and any text other than a tag's canonical text is refused, naming the canonical spelling when it parses. Stored state decodes through Parse.
type Target ¶
Target is one subtitle language a configuration asks for, with the variants wanted in it.
type Variant ¶
type Variant uint8
Variant is what a target asks for. Zero is invalid.
Standard asks for full subtitles, HI for subtitles for the deaf and hard of hearing, Forced for only the lines in another language or on screen.
func (Variant) Flags ¶
Flags is the flags that serve v with nothing extra, which rank first among the files serving it; the zero Flags for an invalid Variant.
func (Variant) MarshalText ¶
MarshalText is standard, hi or forced.
func (*Variant) UnmarshalText ¶
UnmarshalText refuses every spelling but MarshalText's.