Introduce IANA-BCP47 to validate the IETF language code #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello again,
This PR introduces a more robust solution for validating user input of IETF language codes using the
iana-bcp47
library. Compared to the olderbcp47
library, this new implementation validates each subtag against the IANA Language Subtag Registry, rather than relying on a predefined whitelist.Context
highfestiva/bcp47.py#7
In my experience with an older version of
pymkv
, valid language codes such aszh-Hans-CN
would cause aValueError
during validation. These codes are valid according to BCP47 standards but were not included in the whitelist used bybcp47
. To address this issue, I decided to implement a validator that strictly adheres to IANA's rules, which this PR introduces.What's Changed
Previously, the
is_bcp47
function was removed, and user input was directly set as the language metadata. While I have not tested whether incorrect language codes can cause issues when MKV files are loaded in other software, I believe a simple validation mechanism should still be included.With the proposed logic, if the user-entered language code fails validation:
MKVTrack
is set toNone
if the code is invalid.This ensures that language metadata conforms to IANA standards while providing helpful feedback to users.
source of iana-bcp47: https://github.com/Masterain98/iana-bcp47