fix: regression in finding {id}-{id} lang pair from dict name
Some checks failed
SonarCloud / Build and analyze (push) Has been cancelled
deploy_website / deploy (push) Has been cancelled

This commit is contained in:
shenleban tongying 2024-12-12 23:20:39 -05:00 committed by GitHub
parent 6cd878fdcb
commit 13a50dbb6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -275,14 +275,18 @@ quint32 LangCoder::guessId( const QString & lang )
std::pair< quint32, quint32 > LangCoder::findLangIdPairFromName( QString const & name )
{
static QRegularExpression reg( "(?=([a-z]{2,3})-([a-z]{2,3}))", QRegularExpression::CaseInsensitiveOption );
static QRegularExpression reg( "(^|[^a-z])((?<lang1>[a-z]{2,3})-(?<lang2>[a-z]{2,3}))($|[^a-z])",
QRegularExpression::CaseInsensitiveOption );
auto matches = reg.globalMatch( name );
while ( matches.hasNext() ) {
auto m = matches.next();
if ( matches.hasNext() ) {
continue; // We use only the last match, skip previous ones
}
auto fromId = guessId( m.captured( 1 ).toLower() );
auto toId = guessId( m.captured( 2 ).toLower() );
auto fromId = guessId( m.captured( "lang1" ).toLower() );
auto toId = guessId( m.captured( "lang2" ).toLower() );
if ( code2Exists( intToCode2( fromId ) ) && code2Exists( intToCode2( toId ) ) ) {
return { fromId, toId };

View file

@ -10,9 +10,9 @@ Additionally, multiple strategies of automatic grouping are provided:
## Auto groups by dictionary language
For formats like DSL, which has embedded language from / to metadata, GoldenDict will use the dictionary's built-in metadata.
For formats like DSL, which has embedded language from / to metadata, GD will use the dictionary's built-in metadata.
For other formats, GoldenDict will try to extract languages from the dictionary's name or its file name by finding `{id}-{id}` pair. The `{id}` is 2 or 3 letters ISO 639 codes. For example, if a dictionary named `some name en-zh`, it will be automatically grouped into `en-zh`.
For other formats, GD will try finding the last `{id}-{id}` pair delimited by non-alphabets in dictionary name or main file name to extract languages. The `{id}` is 2 or 3 letters ISO 639 codes. For example, if a dictionary named `some name en-zh`, it will be automatically grouped into `en-zh`.
Groups created in this method also include a context menu when right-click the group name, in which you can do additional dictionaries grouping by source or target language and combine dictionaries in more large groups.