Skip to content

Commit 0af1271

Browse files
committed
misc/language.rs: add full BCP 47 compliant pipeline
- Removes custom, incomplete language mapping tables - Adds validation for the BCP 47-defined format - Compares all components separately instead of treating them as the same entity - Adds canonicalization support for ISO 639-{1,2t,2b,3} It is not overly strict in validation to preserve compatibility with "custom" tags. If the language can be parsed and normalized, this will be used; otherwise, it falls back to direct string comparison. For BCP 47 components, all mismatches are penalized equally, with 1000 points deducted per mismatch. This value can be adjusted if needed. This commit should greatly improve support for matching language tags consisting of more than just the primary language and region.
1 parent 3a43522 commit 0af1271

File tree

16 files changed

+354
-386
lines changed

16 files changed

+354
-386
lines changed

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ repos:
1919
hooks:
2020
- id: codespell
2121
args: ["--ignore-words-list", "datas,DNE,enew,HDA,numer,ontop,optionA,Paeth,pathc,inout"]
22-
exclude: ^misc/language.c$

meson.build

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project('mpv',
2-
'c',
2+
['c', 'rust'],
33
license: ['GPL2+', 'LGPL2.1+'],
44
version: files('./MPV_VERSION'),
55
meson_version: '>=1.3.0',
@@ -11,6 +11,8 @@ project('mpv',
1111
'cpp_std=c++20',
1212
'cpp_eh=default',
1313
'warning_level=2',
14+
'rust_std=2021',
15+
'build.rust_std=2021',
1416
]
1517
)
1618

@@ -140,7 +142,6 @@ sources = files(
140142
'misc/dispatch.c',
141143
'misc/io_utils.c',
142144
'misc/json.c',
143-
'misc/language.c',
144145
'misc/natural_sort.c',
145146
'misc/node.c',
146147
'misc/path_utils.c',
@@ -1763,6 +1764,19 @@ major = client_h_define.split('|')[0].split('<<')[0].strip('() ')
17631764
minor = client_h_define.split('|')[1].strip('() ')
17641765
client_api_version = major + '.' + minor + '.0'
17651766

1767+
libmpv_rs = static_library('libmpv_rs',
1768+
files('misc/language.rs'),
1769+
rust_abi: 'c',
1770+
dependencies: [
1771+
dependency('isolang', fallback : ['isolang', 'isolang_dep']),
1772+
dependency('language-tags', fallback : ['language-tags', 'language_tags_dep']),
1773+
],
1774+
)
1775+
libmpv_rs_dep = declare_dependency(link_with: libmpv_rs)
1776+
if get_option('default_library') == 'shared'
1777+
dependencies += declare_dependency(link_with: libmpv_rs)
1778+
endif
1779+
17661780
libmpv = library('mpv', sources, dependencies: dependencies, gnu_symbol_visibility: 'hidden',
17671781
include_directories: incdir_public,
17681782
link_args: cc.get_supported_link_arguments(['-Wl,-Bsymbolic']),
@@ -1780,7 +1794,7 @@ if get_option('libmpv')
17801794
install_headers(headers, subdir: 'mpv')
17811795

17821796
# Allow projects to build with libmpv by cloning into ./subprojects/mpv
1783-
libmpv_dep = declare_dependency(include_directories: incdir_public, link_with: libmpv)
1797+
libmpv_dep = declare_dependency(include_directories: incdir_public, link_with: [libmpv, libmpv_rs])
17841798
meson.override_dependency('mpv', libmpv_dep)
17851799
endif
17861800

@@ -1815,8 +1829,8 @@ if get_option('cplayer')
18151829
rename: 'mpv.svg')
18161830
install_data('etc/mpv-symbolic.svg', install_dir: join_paths(hicolor_dir, 'symbolic', 'apps'))
18171831

1818-
mpv = executable('mpv', main_fn_source, objects: libmpv.extract_all_objects(recursive: true), dependencies: dependencies,
1819-
win_subsystem: get_option('win32-subsystem'), install: true)
1832+
mpv = executable('mpv', main_fn_source, objects: libmpv.extract_all_objects(recursive: true),
1833+
dependencies: dependencies + libmpv_rs_dep, win_subsystem: get_option('win32-subsystem'), install: true)
18201834

18211835
if win32 and get_option('win32-subsystem') != 'console'
18221836
wrapper_sources= 'osdep/win32-console-wrapper.c'

0 commit comments

Comments
 (0)