langcode

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package langcode maps any language identifier subflux meets — a provider payload, an ffprobe stream tag, an arr API response, a config file — onto the one internal code space, and is the only place that mapping happens.

The space is ISO 639-1 two-letter codes plus BrazilianPortuguese. That is not a naming preference: the code becomes a segment of the subtitle filename on disk and part of the bbolt state key, so a code outside the space cannot survive a round trip through a scan.

Canonical is the canonicalizer; FromName sits in front of it with the table of language NAMES the arrs report, because a name carries a product decision a code system cannot express. Both are reached indirectly by design: classify.Alpha2FromAlpha3 and ffmpeg.NormalizeFFprobeLang (through its injected LangMapper, which is what keeps internal/subsync free of provider imports) call in from outside rather than reimplementing the fold. Three hand-written normalizers used to each collapse regions differently; that is what this replaced.

The per-provider dialect tables deliberately stay in their provider packages. They are wire formats owned by one provider's spelling, not identifiers subflux accepts, and each must translate before the code arrives here: hdbits means Brazilian by "br" and Slovenian by "si", which the registry reads as Breton and Sinhala.

Index

Constants

View Source
const BrazilianPortuguese = "pb"

BrazilianPortuguese is subflux's internal code for Brazilian Portuguese.

It is not an ISO 639 code. Subflux invented it so that a Brazilian target stays distinguishable from a European Portuguese one inside a two-letter code space, and it is load-bearing well beyond memory: it appears in user configuration, in the subtitle filename on disk (movie.pb.srt), and in the bbolt state key. langtag rejects it for the same reason it rejects any tag the IANA registry does not list, so it is translated at the boundary instead of being handed to Parse.

Variables

This section is empty.

Functions

func Canonical

func Canonical(raw string) string

Canonical maps one raw language identifier — from a provider payload, an ffprobe stream tag, an arr API response, or a config file — onto subflux's internal code space, and returns "" when the input names no language subflux can represent.

The internal space is ISO 639-1 two-letter codes plus BrazilianPortuguese. That is not a naming preference: the code becomes a segment of the subtitle filename and part of the bbolt state key, so a code outside the space cannot survive a round trip through a scan.

Two rules follow from the space rather than from any standard, which is why they live here and not in langtag:

  • pt-BR yields "pb", not "pt". Region is consulted before it is discarded, because European and Brazilian Portuguese are separate subtitle targets.
  • A language with no ISO 639-1 assignment yields "". langtag's Tag.Language reports a three-letter subtag for those (Cantonese is "yue", Filipino "fil"), and admitting one would place a three-letter code in a two-letter namespace, where it matches no configured target and no display name — silently, forever.

func FromName

func FromName(name string) string

FromName converts a language name or code (as returned by Sonarr/Radarr) to subflux's internal code space. Accepts full names ("english"), the regional-variant names arr reports, and any published language code. Returns "" for unrecognized input.

The name table is consulted first and its value is used verbatim, because a name carries a product decision a code system cannot express: arr's "Portuguese (Brazil)" means the internal "pb", and "Tagalog" means "tl" even though canonicalization would fold that onto the three-letter "fil" and leave the two-letter namespace.

func ParseAudioList

func ParseAudioList(raw string) []string

ParseAudioList splits a comma/slash-separated audio languages string into deduplicated ISO 639-1 codes.

func Valid

func Valid(raw string) bool

Valid reports whether raw is a language code subflux can act on: it names a real language, and it is already written the way the internal space spells it.

The second half is what makes this useful for validating configuration. A code that merely canonicalizes to something valid is not enough, because nothing canonicalizes a configured target at match time — subtitle targets are compared against provider results by exact string. So "eng" names a language and still matches nothing, and telling a user their config is fine would be a lie. Callers report Canonical(raw) as the spelling to use.

Types

This section is empty.

Jump to

Keyboard shortcuts

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