[locale] Tighten up language-matching

- Drop plain startsWith() matching, since we now have "as" and "ast"
   as supported languages, where one name is a prefix of the other.
This commit is contained in:
Adriaan de Groot 2020-01-28 17:35:54 +01:00
parent 49690fc681
commit a09593e4a2

View File

@ -18,7 +18,11 @@
*/
#include "LocaleConfiguration.h"
#include "utils/Logger.h"
#include <QLocale>
#include <QRegularExpression>
LocaleConfiguration::LocaleConfiguration()
: explicit_lang( false )
@ -53,14 +57,9 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
{
QString language = languageLocale.split( '_' ).first();
QStringList linesForLanguage;
for ( const QString& line : availableLocales )
{
if ( line.startsWith( language ) )
{
linesForLanguage.append( line );
}
}
// Either an exact match, or the whole language part matches
// (followed by .<encoding> or _<country>
QStringList linesForLanguage = availableLocales.filter( QRegularExpression( language + "[._]" ) );
QString lang;
if ( linesForLanguage.length() == 0 || languageLocale.isEmpty() )