File: ManagerLanguage.cpp

package info (click to toggle)
ulcc 1.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,420 kB
  • sloc: cpp: 852; xml: 23; sh: 17; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "ManagerLanguage.h"

#include <QRegExp>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonValue>
#include <QFile>
#include <QDebug>

#include "config_ulcc.h"

ManagerLanguage::ManagerLanguage(){
    QFile file;
    file.setFileName(QString(GLOBAL_PATH_USERDATA)+"/langs/langs.json");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug() << tr("Error while opening")+" langs.json" << file.errorString();
    }else{
        QByteArray val = file.readAll();
        file.close();

        QJsonDocument document = QJsonDocument::fromJson(val);
        if (document.isEmpty()){
            qDebug() << "langs.json "+tr("is not valid");
        }else{
            rootLangs = document.object();
        }
    }

}

QString ManagerLanguage::getNativeName(QString lang_code){
    QString languageName="";

    QString lang_code_loc = lang_code;
    if (lang_code_loc.indexOf("_")==-1) lang_code_loc+="_"+lang_code_loc.toUpper();

    if (!rootLangs.value(lang_code).toObject().value("nativeName").isNull()==true){
        languageName = rootLangs.value(lang_code).toObject().value("nativeName").toString();

    }

    if (languageName.isEmpty()){
        QLocale loc(lang_code_loc);
        languageName = loc.nativeLanguageName();
        if (languageName.isEmpty()) languageName= QLocale::languageToString(loc.language());
    }

    if (!languageName.isEmpty()) languageName[0]=languageName[0].toUpper();

    if (languageName.isEmpty() or languageName=="C"){
            languageName=lang_code;
    }


    return languageName;
}