Skip to content

Commit

Permalink
player/loadfile: match starting part of the language code
Browse files Browse the repository at this point in the history
This allows to match fr-CA directly or match fr- to allow fr-CA and
fr-FR.
  • Loading branch information
kasper93 committed Apr 17, 2024
1 parent 7d30a80 commit 49c18f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ Track Selection

- ``mpv dvd://1 --alang=hu,en`` chooses the Hungarian language track
on a DVD and falls back on English if Hungarian is not available.
- ``mpv --alang=jpn example.mkv`` plays a Matroska file with Japanese
- ``mpv --alang=ja-JP,jpn example.mkv`` plays a Matroska file with Japanese
audio.

``--slang=<languagecode[,languagecode,...]>``
Specify a priority list of subtitle languages to use. Different container
formats employ different language codes. DVDs use ISO 639-1 two letter
language codes, Matroska uses ISO 639-2 three letter language codes while
OGM uses a free-form identifier. See also ``--sid``.
Equivalent to ``--alang``, for subtitle tracks.

This is a string list option. See `List Options`_ for details.

.. admonition:: Examples

- ``mpv dvd://1 --slang=hu,en`` chooses the Hungarian subtitle track on
a DVD and falls back on English if Hungarian is not available.
- ``mpv --slang=jpn example.mkv`` plays a Matroska file with Japanese
- ``mpv --slang=ja-JP,jpn example.mkv`` plays a Matroska file with Japanese
subtitles.
- ``mpv --slang=pt-BR,pt-PT example.mkv`` plays a Matroska file with Brazilian
Portuguese subtitles if available, and otherwise any Portuguese subtitles.
- ``mpv --slang=pt example.mkv`` plays a Matroska file with any Portuguese
subtitles.

``--vlang=<...>``
Expand Down
2 changes: 1 addition & 1 deletion player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static int match_lang(char **langs, const char *lang)
if (!lang)
return 0;
for (int idx = 0; langs && langs[idx]; idx++) {
if (lang && strcasecmp(langs[idx], lang) == 0)
if (lang && strncasecmp(langs[idx], lang, strlen(langs[idx])) == 0)
return INT_MAX - idx;
}
return 0;
Expand Down

0 comments on commit 49c18f2

Please sign in to comment.