<a id="languages"></a>

# Language definitions

To present different translations properly, info about language name,
text direction, plural definitions and language code are needed.

<a id="included-languages"></a>

## Built-in language definitions

Definitions for about 800 languages are included in Weblate and the list is
extended in every release. Whenever Weblate is upgraded (more specifically
whenever [`migrate`](https://docs.weblate.org/no/latest/admin/management.md#weblate-admin-migrate) is executed, see
[Generic upgrade instructions](https://docs.weblate.org/no/latest/admin/upgrade.md#generic-upgrade-instructions)) the database of languages is updated to
include all language definitions shipped in Weblate.

Norwegian Bokmål now uses `nb` as its built-in language code. Weblate also
accepts `nb_NO` for existing files and locally added languages. Language
setup moves existing `nb_NO` languages to `nb` unless their translations
or settings conflict with an existing `nb` language. Translation file names
remain unchanged.

This feature can be disabled using [`UPDATE_LANGUAGES`](https://docs.weblate.org/no/latest/admin/config.md#std-setting-UPDATE_LANGUAGES). You can also
enforce updating the database to match Weblate built-in data using
[`setuplang`](https://docs.weblate.org/no/latest/admin/management.md#weblate-admin-setuplang).

#### SEE ALSO
* [Extending built-in language definitions](https://docs.weblate.org/no/latest/contributing/modules.md#extending-languages)
* [Current language definitions](https://github.com/WeblateOrg/language-data/blob/main/languages.csv)

<a id="language-parsing-codes"></a>

## Parsing language codes

While parsing translations, Weblate attempts to map language code (usually the
ISO 639-1 one) from the [File mask](https://docs.weblate.org/no/latest/admin/projects.md#component-filemask) to any existing language
object.

You can further adjust this mapping at project level by [Language aliases](https://docs.weblate.org/no/latest/admin/projects.md#project-language-aliases).

If no exact match can be found, an attempt will be made
to best fit it into an existing language. Following steps are tried:

* Case insensitive lookups.
* Normalizing underscores and dashes.
* Looking up built-in language aliases.
* Looking up by language name.
* Ignoring the default country code for a given language—choosing `cs` instead of `cs_CZ`.

Should that also fail, a new language definition will be created using the
defaults (left to right text direction, one plural). The automatically created
language with code `xx_XX` will be named as xx_XX (generated).
You might want to change this in the admin interface later, (see
[Changing language definitions](#changing-languages)) and report it to the issue tracker (see
[Contributing to Weblate](https://docs.weblate.org/no/latest/contributing/index.md#contributing)), so that the proper definition can be added to the
upcoming Weblate release.

#### HINT
In case you see something unwanted as a language, you might want to adjust
[Language filter](https://docs.weblate.org/no/latest/admin/projects.md#component-language-regex) to ignore such file when parsing
translations.

#### SEE ALSO
* [Language code](#language-code)
* [Adding new translations](https://docs.weblate.org/no/latest/devel/translations.md#adding-translation)

<a id="changing-languages"></a>

## Changing language definitions

You can change language definitions in the languages interface
(`/languages/` URL).

While editing, ensure all fields are correct (especially plurals and
text direction), otherwise translators will be unable to properly edit
those translations.

#### HINT
Please consider contributing your changes back, see [Extending built-in language definitions](https://docs.weblate.org/no/latest/contributing/modules.md#extending-languages).

<a id="ambiguous-languages"></a>

## Ambiguous language codes and macrolanguages

In many cases it is not a good idea to use macrolanguage code for a
translation. The typical problematic case might be Kurdish language, which
might be written in Arabic or Latin script, depending on actual variant. To get
correct behavior in Weblate, it is recommended to use individual language codes
only and avoid macrolanguages.

#### SEE ALSO
[Macrolanguages at Wikipedia](https://en.wikipedia.org/wiki/ISO_639_macrolanguage)

<a id="id1"></a>

## Language definitions

Each language consists of following fields:

<a id="language-code"></a>

### Language code

Code identifying the language. Weblate prefers two letter codes as defined by
[ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1), but uses [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2) or [ISO 639-3](https://en.wikipedia.org/wiki/ISO_639-3) codes for languages that do not
have two letter code. It can also support extended codes as defined by [BCP 47](https://www.rfc-editor.org/info/bcp47).

#### SEE ALSO
* [Parsing language codes](#language-parsing-codes)
* [Adding new translations](https://docs.weblate.org/no/latest/devel/translations.md#adding-translation)

<a id="language-name"></a>

### Language name

Visible name of the language. The language names included in Weblate are also being localized depending on user interface language.

<a id="language-direction"></a>

### Text direction

Determines whether language is written right to left or left to right. This
property is autodetected correctly for most of the languages.

<a id="language-population"></a>

### Number of speakers

Number of worldwide speakers of this language.

<a id="plural-definitions"></a>

## Plural definitions

Weblate comes with a built-in set of plural definitions. These are based on
file-format specifications, CLDR, and other sources.

#### WARNING
Doing changes to the built-in plural definitions will most likely won’t have
desired effect, as these rules need to match underlying implementation.

Changing plural number or formula will affect only displaying of the
strings, but not parsing and storing strings to the files. Should you think
Weblate behaves incorrectly, please file an issue in our issue tracker.

<a id="plural-number"></a>

### Plural number

Number of plurals used in the language.

<a id="plural-formula"></a>

### Plural formula

Gettext compatible plural formula used to determine which plural form is used for given count.

The formula uses the same expression syntax as the `plural=` part of the
Gettext `Plural-Forms` header. The `nplurals` value sets how many plural
forms the language has, and the formula returns the zero-based index of the
plural form to use for a count `n`.

Weblate validates the formula using the Gettext parser provided by Python.
The accepted syntax is a C-like integer expression with `n` as the only
variable. It can use decimal numbers, parentheses, arithmetic operators
(`+`, `-`, `*`, `/`, `%`), comparison and equality operators,
logical operators (`&&`, `||`, `!`), and the ternary operator
(`condition ? value1 : value2`). The result must be between `0` and
`nplurals - 1`.

For example, English uses:

```text
nplurals=2; plural=n != 1;
```

#### SEE ALSO
* [Plurals](https://docs.weblate.org/no/latest/user/translating.md#plurals)
* [GNU gettext manual for plural forms](https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms)
* [GNU gettext plural formula parser](https://cgit.git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plural.y)
* [Language Plural Rules by the Unicode Consortium](https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html)
