src/hbcore/i18n/hblocaleutil.cpp
author hgs
Mon, 18 Oct 2010 18:23:13 +0300
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/****************************************************************************
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
** All rights reserved.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
** Contact: Nokia Corporation (developer.feedback@nokia.com)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
** This file is part of the HbCore module of the UI Extensions for Mobile.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
** GNU Lesser General Public License Usage
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
** This file may be used under the terms of the GNU Lesser General Public
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
** License version 2.1 as published by the Free Software Foundation and
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
** appearing in the file LICENSE.LGPL included in the packaging of this file.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
** Please review the following information to ensure the GNU Lesser General
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
** Public License version 2.1 requirements will be met:
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
** In addition, as a special exception, Nokia gives you certain additional
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
** rights.  These rights are described in the Nokia Qt LGPL Exception
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
** If you have questions regarding the use of this file, please contact
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
** Nokia at developer.feedback@nokia.com.
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
**
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
****************************************************************************/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include <QFile>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <QLocale>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include <QTimer>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <QHash>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include <QHashIterator>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include <QTextStream>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
#include <QTranslator>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
#include <QTextCodec>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include <QCoreApplication>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include <QStringList>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
#if defined(Q_OS_SYMBIAN)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
#include <e32lang.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
#include <e32property.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
#include <centralrepository.h> 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
#include <hal.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
#include <syslangutil.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
#include <CommonEngineDomainCRKeys.h> //Ui language
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
#endif // Q_OS_SYMBIAN
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
#include <hbglobal.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
#include <hblocaleutil.h>
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
#if defined(Q_OS_SYMBIAN)
34
hgs
parents: 7
diff changeset
    50
#define LANGUAGE_LIST_FILE "/resource/hb/translations/language_list.txt"
hgs
parents: 7
diff changeset
    51
#define LANGUAGE_MAPPINGS_FILE "/resource/hb/translations/locale_mappings.txt"
hgs
parents: 7
diff changeset
    52
#define LANGUAGE_TRANSLATOR_PATH "/resource/hb/translations/languages"
hgs
parents: 7
diff changeset
    53
#define REGION_TRANSLATOR_PATH "/resource/hb/translations/regions"
hgs
parents: 7
diff changeset
    54
#define COLLATION_TRANSLATOR_PATH "/resource/hb/translations/collations"
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
34
hgs
parents: 7
diff changeset
    56
#define LANGUAGE_ID_PREFIX "txt_language"
hgs
parents: 7
diff changeset
    57
#define REGION_ID_PREFIX "txt_region"
hgs
parents: 7
diff changeset
    58
#define COLLATION_ID_PREFIX "txt_collation"
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
#define COLLATION_DLL_PREFIX_POSITION 3
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
#endif // Q_OS_SYMBIAN
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
/*!
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
    @beta
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
    @hbcore
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    \class HbLocaleUtil
34
hgs
parents: 7
diff changeset
    67
    \brief The HbLocaleUtil class supports querying the supported languages, regions and collations, and activating them.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
     
34
hgs
parents: 7
diff changeset
    69
    With HbLocaleUtil, you can query the supported languages, regions and 
hgs
parents: 7
diff changeset
    70
    collations from the device, and the ones currently set in the device. You 
hgs
parents: 7
diff changeset
    71
    can then use this data to activate the language, region and collation in the 
hgs
parents: 7
diff changeset
    72
    device; either individually, or as a set determined by the specified 
hgs
parents: 7
diff changeset
    73
    language.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    
34
hgs
parents: 7
diff changeset
    75
    HbLocaleUtil returns the data from the device as identifiers. The language 
hgs
parents: 7
diff changeset
    76
    and collation identifiers typically correspond to two-letter ISO 639 
hgs
parents: 7
diff changeset
    77
    language codes. However, some languages and collations use a combination of 
hgs
parents: 7
diff changeset
    78
    an ISO 639 language code and an ISO 3166 country code, separated by an 
hgs
parents: 7
diff changeset
    79
    underscore character. Region identifiers always correspond to a two-letter 
hgs
parents: 7
diff changeset
    80
    ISO 3166 country code.
hgs
parents: 7
diff changeset
    81
    
hgs
parents: 7
diff changeset
    82
    HbLocaleUtil also provides functions for converting language, region and 
hgs
parents: 7
diff changeset
    83
    collation identifiers to their localized names. 
hgs
parents: 7
diff changeset
    84
    
hgs
parents: 7
diff changeset
    85
    Example:
hgs
parents: 7
diff changeset
    86
    \snippet{unittest_hblocaleutil/unittest_hblocaleutil.cpp,1}
hgs
parents: 7
diff changeset
    87
    
hgs
parents: 7
diff changeset
    88
    
hgs
parents: 7
diff changeset
    89
    \sa HbStringUtil, HbExtendedLocale
hgs
parents: 7
diff changeset
    90
    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
*/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
#if defined(Q_OS_SYMBIAN)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
struct HbLocaleMapping
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
    int symLangValue;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
    QString languageDllId;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
    QString collationDllId;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
    QString regionDllId;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
    QString langName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
    QString regName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
    QString collName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
};
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
QList<HbLocaleMapping> mappingList;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
QStringList availRegions;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
QHash<QString, QString> locRegionNames;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
QStringList availCollations;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
QHash<QString, QString> locCollationNames;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
/*!
34
hgs
parents: 7
diff changeset
   113
    \relates HbLocaleUtil
hgs
parents: 7
diff changeset
   114
    
hgs
parents: 7
diff changeset
   115
    Reads language, region and collation mappings.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
*/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
void readMappings()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
    QString path = "c:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
    path += QString(LANGUAGE_MAPPINGS_FILE);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
    QFile* file = new QFile(path);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
    if (!file->exists() ) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
        path = "z:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
        path += QString(LANGUAGE_MAPPINGS_FILE);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
        delete file;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   126
        file = new QFile(path);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
    if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
        delete file;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
        return;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   132
    QTextStream in(file);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   133
    while (!in.atEnd()) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   134
        QString line = in.readLine(256);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   135
        if (!line.isEmpty()) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
            QStringList list = line.split(',', QString::SkipEmptyParts);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
            if (list.count() < 7) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
                continue;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
            }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
            QString strCode = list[0];
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
            QString strLang = list[1];
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
            QString strRegion = list[2];
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
            QString strCollation = list[3];
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
            QString lanName = list[4]; //en_GB
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
            QString region = list[5]; //en_GB
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
            QString collation = list[6]; //en_GB
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
            
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
            bool ok;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
            int code = strCode.toUInt(&ok);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
            if (!ok) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
                continue;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
            }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
            
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
            HbLocaleMapping map;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
            map.symLangValue = code;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
            map.languageDllId = strLang;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
            map.collationDllId = strCollation;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
            map.regionDllId = strRegion;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
            map.langName = lanName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
            map.regName = region;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
            map.collName = collation;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
            mappingList.append(map);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
    delete file;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
    return;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
#endif // Q_OS_SYMBIAN
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
34
hgs
parents: 7
diff changeset
   170
/*!
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
34
hgs
parents: 7
diff changeset
   172
    Returns the identifier of the current UI language. Typically the language 
hgs
parents: 7
diff changeset
   173
    identifier is an ISO 639 language code, but in some cases, it is a 
hgs
parents: 7
diff changeset
   174
    combination of an ISO 639 language code and an ISO 3166 country code. For 
hgs
parents: 7
diff changeset
   175
    example, for UK English, this returns "en", and for US English, this returns 
hgs
parents: 7
diff changeset
   176
    "en_US".
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
    
34
hgs
parents: 7
diff changeset
   178
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   179
    platforms, always returns an empty QString.
hgs
parents: 7
diff changeset
   180
    
hgs
parents: 7
diff changeset
   181
    \sa supportedLanguages(), localisedLanguageName(), changeLanguage(), languageRegionMappings()
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
QString HbLocaleUtil::currentLanguage()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
{
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   186
#if defined(Q_OS_SYMBIAN)
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   187
    TLanguage l = User::Language();
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   188
    
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   189
    if(mappingList.isEmpty()) {
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   190
        readMappings();
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   191
    }
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   192
    
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   193
    for (int i = 0; i < mappingList.count(); ++i) {
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   194
        HbLocaleMapping mapping = mappingList.at(i);
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   195
        if (mapping.symLangValue == l) {
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   196
            return mapping.langName;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
        }
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   198
    }
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   199
#endif
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   200
   return QString();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
/*!
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
    
34
hgs
parents: 7
diff changeset
   205
    Returns the identifiers of the languages supported on the device. Typically 
hgs
parents: 7
diff changeset
   206
    the language identifier is an ISO 639 language code, but in some cases, it 
hgs
parents: 7
diff changeset
   207
    is a combination of an ISO 639 language code and an ISO 3166 country code. 
hgs
parents: 7
diff changeset
   208
    For example, for UK English, this returns "en", and for US English, this 
hgs
parents: 7
diff changeset
   209
    returns "en_US".
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    
34
hgs
parents: 7
diff changeset
   211
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   212
    platforms, always returns an empty QStringList.
hgs
parents: 7
diff changeset
   213
    
hgs
parents: 7
diff changeset
   214
    \sa localisedLanguageName(), currentLanguage(), changeLanguage(), changeLocale()
hgs
parents: 7
diff changeset
   215
    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
*/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
QStringList HbLocaleUtil::supportedLanguages()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
#if defined(Q_OS_SYMBIAN)   
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
    QStringList languages; 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   221
    CArrayFixFlat<TInt>* systemEpocLanguageCodes = 0;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
    TInt error = SysLangUtil::GetInstalledLanguages( systemEpocLanguageCodes );
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
    if ( error != KErrNone ) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   224
        delete systemEpocLanguageCodes;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
        return languages;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
    if(mappingList.isEmpty()) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
    for (int i = 0; i < systemEpocLanguageCodes->Count(); ++i) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   233
        int code = systemEpocLanguageCodes->At(i);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
        for (int j = 0; j < mappingList.count(); ++j) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   235
            HbLocaleMapping map = mappingList.at(j);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   236
            if (map.symLangValue == code) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
                languages.append(map.langName);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   238
                break;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   239
            }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   242
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   243
    delete systemEpocLanguageCodes;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   244
    return languages;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   245
#else 
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   246
    return QStringList();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   247
#endif
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   248
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   250
/*!
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
    
34
hgs
parents: 7
diff changeset
   252
    Returns the localised language name for the specified language identifier. 
hgs
parents: 7
diff changeset
   253
    If the translation fails, returns an empty QString.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
    
34
hgs
parents: 7
diff changeset
   255
    \param language The two- or five-letter language identifier that corresponds to one of the following:
hgs
parents: 7
diff changeset
   256
    - An identifier returned by supportedLanguages() or currentLanguage()
hgs
parents: 7
diff changeset
   257
    - An HbLanguageRegionMapping::languageId string
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   258
    
34
hgs
parents: 7
diff changeset
   259
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   260
    platforms, always returns an empty QString.
hgs
parents: 7
diff changeset
   261
    
hgs
parents: 7
diff changeset
   262
    \sa changeLanguage(), currentLanguage()
hgs
parents: 7
diff changeset
   263
 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
QString HbLocaleUtil::localisedLanguageName( const QString &language )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
#if defined(Q_OS_SYMBIAN)   
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   268
    QTranslator translator;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
    QString path = "c:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   270
    path += QString(LANGUAGE_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   271
    if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   272
        path = "z:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   273
        path += QString(LANGUAGE_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
        if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
            return QString("");
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
        } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   277
    } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   278
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
    QCoreApplication::installTranslator(&translator);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   280
    QString languageName = QString(LANGUAGE_ID_PREFIX);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   281
    languageName += '_';
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   282
    languageName += language;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   283
    QString translated = hbTrId(languageName.toAscii().constData());  
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
    if (translated == languageName) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   285
        return QString("");
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   286
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   287
    return translated;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   288
#else 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
    Q_UNUSED(language); 
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   290
    return QString();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   291
#endif
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   292
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
/*!
34
hgs
parents: 7
diff changeset
   295
hgs
parents: 7
diff changeset
   296
    Changes the system language to the one specified in \a language.
hgs
parents: 7
diff changeset
   297
  
hgs
parents: 7
diff changeset
   298
    \param language The language identifier. This must correspond to an 
hgs
parents: 7
diff changeset
   299
    identifier returned by supportedLanguages(), or an 
hgs
parents: 7
diff changeset
   300
    HbLanguageRegionMapping::languageId string.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
    
34
hgs
parents: 7
diff changeset
   302
    \return \c true if successful, otherwise \c false.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
    
34
hgs
parents: 7
diff changeset
   304
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   305
    platforms, always returns \c false.
hgs
parents: 7
diff changeset
   306
    
hgs
parents: 7
diff changeset
   307
    \sa localisedLanguageName(), currentLanguage()
hgs
parents: 7
diff changeset
   308
    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
bool HbLocaleUtil::changeLanguage( const QString &language )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   311
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
#if defined(Q_OS_SYMBIAN)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
    if(mappingList.isEmpty()) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   315
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   316
    int lanCode = -1;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
    for (int i = 0;  i < mappingList.count(); ++i) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
        HbLocaleMapping map = mappingList.at(i);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
        if (map.langName == language) {
34
hgs
parents: 7
diff changeset
   320
            int retVal = -1;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   321
            lanCode = map.symLangValue;
34
hgs
parents: 7
diff changeset
   322
            retVal = SysLangUtil::ChangeLanguage(lanCode);
hgs
parents: 7
diff changeset
   323
            if (!retVal) {
hgs
parents: 7
diff changeset
   324
                // Never set Language code 0 to HAL
hgs
parents: 7
diff changeset
   325
                if ( language != 0 ) {
hgs
parents: 7
diff changeset
   326
                    HAL::Set( HAL::ELanguageIndex, lanCode );
hgs
parents: 7
diff changeset
   327
                }
hgs
parents: 7
diff changeset
   328
                return true;
hgs
parents: 7
diff changeset
   329
            }
hgs
parents: 7
diff changeset
   330
            else {
hgs
parents: 7
diff changeset
   331
                return false;
hgs
parents: 7
diff changeset
   332
            }
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
        }
34
hgs
parents: 7
diff changeset
   334
    }        
hgs
parents: 7
diff changeset
   335
    return false;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   336
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
    Q_UNUSED(language);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
    return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   339
#endif
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   340
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
/*!
34
hgs
parents: 7
diff changeset
   343
    
hgs
parents: 7
diff changeset
   344
    Returns the identifiers of regions supported on the device. The region 
hgs
parents: 7
diff changeset
   345
    identifier is a two-letter ISO 3166 code, for example, "GB" for United 
hgs
parents: 7
diff changeset
   346
    Kingdom.
hgs
parents: 7
diff changeset
   347
    
hgs
parents: 7
diff changeset
   348
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   349
    platforms, always returns an empty QStringList.
hgs
parents: 7
diff changeset
   350
    
hgs
parents: 7
diff changeset
   351
    \sa localisedRegionName(), currentRegion(), changeRegion()
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   353
*/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   354
QStringList HbLocaleUtil::supportedRegions()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   356
#if defined(Q_OS_SYMBIAN)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   357
    if(!availRegions.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   358
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
        return availRegions;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   360
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   361
34
hgs
parents: 7
diff changeset
   362
    QStringList regions; 
hgs
parents: 7
diff changeset
   363
    CArrayFixFlat<TInt>* systemEpocRegionCodes = 0;
hgs
parents: 7
diff changeset
   364
    TInt error = SysLangUtil::GetInstalledRegions( systemEpocRegionCodes );
hgs
parents: 7
diff changeset
   365
    if ( error != KErrNone ) {
hgs
parents: 7
diff changeset
   366
        delete systemEpocRegionCodes;
hgs
parents: 7
diff changeset
   367
        return regions;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   368
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   369
    
34
hgs
parents: 7
diff changeset
   370
    if(mappingList.isEmpty()) {
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   371
        readMappings();
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   372
    }
34
hgs
parents: 7
diff changeset
   373
    
hgs
parents: 7
diff changeset
   374
    for (int i = 0; i < systemEpocRegionCodes->Count(); ++i) {
hgs
parents: 7
diff changeset
   375
        int code = systemEpocRegionCodes->At(i);
hgs
parents: 7
diff changeset
   376
        for (int j = 0; j < mappingList.count(); ++j) {
hgs
parents: 7
diff changeset
   377
            HbLocaleMapping map = mappingList.at(j);
hgs
parents: 7
diff changeset
   378
            QString dllid = map.regionDllId;
hgs
parents: 7
diff changeset
   379
            bool ok;
hgs
parents: 7
diff changeset
   380
            int symRegionValue = dllid.toInt(&ok,10);
hgs
parents: 7
diff changeset
   381
            if (symRegionValue == code) {
hgs
parents: 7
diff changeset
   382
                availRegions.append(map.regName);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   383
                break;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   384
            }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   385
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   386
    }
34
hgs
parents: 7
diff changeset
   387
    
hgs
parents: 7
diff changeset
   388
    delete systemEpocRegionCodes;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   389
    return availRegions;
34
hgs
parents: 7
diff changeset
   390
#else 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   391
    return QStringList();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   392
#endif
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   393
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   394
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   395
/*!
34
hgs
parents: 7
diff changeset
   396
hgs
parents: 7
diff changeset
   397
    Returns the localised region name for the given two-letter region 
hgs
parents: 7
diff changeset
   398
    identifier. If the translation fails, returns an empty QString.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   399
    
34
hgs
parents: 7
diff changeset
   400
    \param region The region identifier that corresponds to one of the following:
hgs
parents: 7
diff changeset
   401
    - An identifier returned by supportedRegions() or currentRegion()
hgs
parents: 7
diff changeset
   402
    - An HbLanguageRegionMapping::regionId string
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   403
    
34
hgs
parents: 7
diff changeset
   404
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   405
    platforms, always returns an empty QString.
hgs
parents: 7
diff changeset
   406
    
hgs
parents: 7
diff changeset
   407
    \sa currentRegion(), changeRegion()
hgs
parents: 7
diff changeset
   408
  
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   409
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   410
QString HbLocaleUtil::localisedRegionName( const QString &region ) 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   411
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
#if defined(Q_OS_SYMBIAN)       
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   413
    if(locRegionNames.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   415
        QTranslator translator;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   416
        QString path = "c:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   417
        path += QString(REGION_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   418
        if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   419
            path = "z:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   420
            path += QString(REGION_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   421
            if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   422
                return QString("");
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   423
            } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   424
        } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   425
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   426
        QCoreApplication::installTranslator(&translator);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   427
            
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   428
        if(mappingList.isEmpty()) 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   429
        {
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   430
            readMappings();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   431
        }
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   432
        int cnt = mappingList.count();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   433
        for(int i = 0 ; i < cnt; i++ )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   434
        {
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   435
            HbLocaleMapping map = mappingList.at(i);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   436
            QString regionName = QString(REGION_ID_PREFIX);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   437
            regionName += '_';
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   438
            regionName += map.regName;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   439
            QString locRegName = hbTrId(regionName.toAscii().constData());
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   440
            if(locRegName != regionName)
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   441
                locRegionNames.insert(map.regName, locRegName);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   442
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   443
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   444
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   445
    return locRegionNames.value(region);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   446
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   447
    Q_UNUSED(region);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   448
    return QString();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   449
#endif    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   450
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   451
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   452
/*!
34
hgs
parents: 7
diff changeset
   453
    Changes the system region to the one specified in \a region.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   454
34
hgs
parents: 7
diff changeset
   455
    \param region The region identifier. This must correspond to an identifier 
hgs
parents: 7
diff changeset
   456
    returned by supportedRegions(), or an HbLanguageRegionMapping::regionId 
hgs
parents: 7
diff changeset
   457
    string.
hgs
parents: 7
diff changeset
   458
    
hgs
parents: 7
diff changeset
   459
    \return \c true if successful, otherwise \c false.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   460
    
34
hgs
parents: 7
diff changeset
   461
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   462
    platforms, always returns \c false.
hgs
parents: 7
diff changeset
   463
    
hgs
parents: 7
diff changeset
   464
    \sa localisedRegionName(), currentRegion()
hgs
parents: 7
diff changeset
   465
    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   466
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   467
bool HbLocaleUtil::changeRegion( const QString &region )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   468
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   469
#if defined(Q_OS_SYMBIAN)   
34
hgs
parents: 7
diff changeset
   470
   
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   471
    if(mappingList.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   472
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   473
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   474
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   475
    int count = mappingList.count();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   476
    for (int j = 0; j < count; j++)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   477
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   478
        HbLocaleMapping mapping = mappingList.at(j);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   479
        QString name = mapping.regName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   480
        if(name == region)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   481
        {
34
hgs
parents: 7
diff changeset
   482
            int retVal = -1;
hgs
parents: 7
diff changeset
   483
            QString dllid = mapping.regionDllId;
hgs
parents: 7
diff changeset
   484
            bool ok;
hgs
parents: 7
diff changeset
   485
            int regioncode = dllid.toInt(&ok,10);
hgs
parents: 7
diff changeset
   486
            if(!regioncode)
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   487
                return false;
34
hgs
parents: 7
diff changeset
   488
            retVal = SysLangUtil::ChangeRegion(regioncode);
hgs
parents: 7
diff changeset
   489
            if(retVal != 0)
hgs
parents: 7
diff changeset
   490
                return false;
hgs
parents: 7
diff changeset
   491
            else
hgs
parents: 7
diff changeset
   492
                return true;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   493
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   494
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   495
    return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   496
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   497
    Q_UNUSED(region);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   498
    return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   499
#endif    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   500
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   501
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   502
/*!
34
hgs
parents: 7
diff changeset
   503
    
hgs
parents: 7
diff changeset
   504
    Returns the identifier of the current region. The region identifier is a 
hgs
parents: 7
diff changeset
   505
    two-letter ISO 3166 code, for example, "GB" for United Kingdom.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   506
34
hgs
parents: 7
diff changeset
   507
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   508
    platforms, always returns an empty QString.
hgs
parents: 7
diff changeset
   509
    
hgs
parents: 7
diff changeset
   510
    \sa supportedRegions(), localisedRegionName(), changeRegion(), languageRegionMappings()
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   511
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   512
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   513
QString HbLocaleUtil::currentRegion()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   514
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   515
#if defined(Q_OS_SYMBIAN)      
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   516
    if(mappingList.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   517
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   518
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   519
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   520
    TRegionCode reg = User::RegionCode();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   521
    int cnt = mappingList.count();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   522
    for(int i = 0; i < cnt; i++)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   523
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   524
        HbLocaleMapping mapping = mappingList.at(i);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   525
        int dllid = mapping.regionDllId.toInt();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   526
        if(dllid == reg)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   527
        {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   528
            return mapping.regName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   529
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   530
    }
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   531
#endif    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   532
    return QString();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   533
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   534
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   535
/*!
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   536
    
34
hgs
parents: 7
diff changeset
   537
    Returns the identifiers of the collations supported on a device. Typically 
hgs
parents: 7
diff changeset
   538
    the collation identifier is an ISO 639 language code, but in some cases, it 
hgs
parents: 7
diff changeset
   539
    is a combination of an ISO 639 language code and an ISO 3166 country code. 
hgs
parents: 7
diff changeset
   540
    For example, for UK English, this returns "en", and for US English, this 
hgs
parents: 7
diff changeset
   541
    returns "en_US".
hgs
parents: 7
diff changeset
   542
    
hgs
parents: 7
diff changeset
   543
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   544
    platforms, always returns an empty QStringList.
hgs
parents: 7
diff changeset
   545
    
hgs
parents: 7
diff changeset
   546
    \sa localisedCollationName(), currentCollation(), changeCollation()
hgs
parents: 7
diff changeset
   547
 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   548
*/
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   549
QStringList HbLocaleUtil::supportedCollations()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   550
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   551
#if defined(Q_OS_SYMBIAN)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   552
    if(!availCollations.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   553
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   554
        return availCollations;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   555
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   556
34
hgs
parents: 7
diff changeset
   557
    QStringList collations; 
hgs
parents: 7
diff changeset
   558
    CArrayFixFlat<TInt>* systemEpocCollationCodes = 0;
hgs
parents: 7
diff changeset
   559
    TInt error = SysLangUtil::GetInstalledCollations( systemEpocCollationCodes );
hgs
parents: 7
diff changeset
   560
    if ( error != KErrNone ) {
hgs
parents: 7
diff changeset
   561
        delete systemEpocCollationCodes;
hgs
parents: 7
diff changeset
   562
        return collations;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   563
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   564
    
34
hgs
parents: 7
diff changeset
   565
    if(mappingList.isEmpty()) {
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   566
        readMappings();
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   567
    }
34
hgs
parents: 7
diff changeset
   568
    
hgs
parents: 7
diff changeset
   569
    for (int i = 0; i < systemEpocCollationCodes->Count(); ++i) {
hgs
parents: 7
diff changeset
   570
        int code = systemEpocCollationCodes->At(i);
hgs
parents: 7
diff changeset
   571
        for (int j = 0; j < mappingList.count(); ++j) {
hgs
parents: 7
diff changeset
   572
            HbLocaleMapping map = mappingList.at(j);
hgs
parents: 7
diff changeset
   573
            bool ok;
hgs
parents: 7
diff changeset
   574
            int symCollatValue = map.collationDllId.toInt(&ok,10);
hgs
parents: 7
diff changeset
   575
            if (symCollatValue == code) {
hgs
parents: 7
diff changeset
   576
                availCollations.append(map.collName);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   577
                break;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   578
            }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   579
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   580
    }
34
hgs
parents: 7
diff changeset
   581
    
hgs
parents: 7
diff changeset
   582
    delete systemEpocCollationCodes;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   583
    return availCollations;
34
hgs
parents: 7
diff changeset
   584
#else 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   585
    return QStringList();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   586
#endif
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   587
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   588
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   589
/*!
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   590
    
34
hgs
parents: 7
diff changeset
   591
    Returns the localised collation name for the given collation identifier. If 
hgs
parents: 7
diff changeset
   592
    the translation fails, returns an empty QString.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   593
    
34
hgs
parents: 7
diff changeset
   594
    \param collation The region collation identifier that corresponds to one of the following:
hgs
parents: 7
diff changeset
   595
    - An identifier returned by supportedCollations() or currentCollation()
hgs
parents: 7
diff changeset
   596
    - An HbLanguageRegionMapping::collationId string
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   597
    
34
hgs
parents: 7
diff changeset
   598
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   599
    platforms, always returns an empty QString.
hgs
parents: 7
diff changeset
   600
    
hgs
parents: 7
diff changeset
   601
    \sa currentCollation(), changeCollation()
hgs
parents: 7
diff changeset
   602
  
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   603
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   604
QString HbLocaleUtil::localisedCollationName( const QString &collation ) 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   605
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   606
#if defined(Q_OS_SYMBIAN)       
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   607
    if(locCollationNames.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   608
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   609
        QTranslator translator;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   610
        QString path = "c:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   611
        path += QString(COLLATION_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   612
        if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   613
            path = "z:";
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   614
            path += QString(COLLATION_TRANSLATOR_PATH);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   615
            if (!translator.load(path)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   616
                return QString("");
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   617
            } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   618
        } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   619
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   620
        QCoreApplication::installTranslator(&translator);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   621
            
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   622
        if(mappingList.isEmpty()) 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   623
        {
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   624
            readMappings();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   625
        }
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   626
        int cnt = mappingList.count();
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   627
        for(int i = 0 ; i < cnt; i++ )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   628
        {
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   629
            HbLocaleMapping map = mappingList.at(i);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   630
            QString collationName = QString(COLLATION_ID_PREFIX);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   631
            collationName += '_';
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   632
            collationName += map.collName;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   633
            QString locColName = hbTrId(collationName.toAscii().constData());
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   634
            if(locColName != collationName)
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   635
                locCollationNames.insert(map.collName, locColName);
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   636
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   637
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   638
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   639
    return locCollationNames.value(collation);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   640
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   641
    Q_UNUSED(collation);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   642
    return QString();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   643
#endif    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   644
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   645
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   646
/*!
34
hgs
parents: 7
diff changeset
   647
    
hgs
parents: 7
diff changeset
   648
    Changes the system collation to the one specified in \a collation.
hgs
parents: 7
diff changeset
   649
    
hgs
parents: 7
diff changeset
   650
    \param collation The collation identifier. This must correspond to an 
hgs
parents: 7
diff changeset
   651
    identifier returned by supportedCollations(), or an 
hgs
parents: 7
diff changeset
   652
    HbLanguageRegionMapping::collationId string.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   653
    
34
hgs
parents: 7
diff changeset
   654
    \return \c true if successful, otherwise \c false.
hgs
parents: 7
diff changeset
   655
    
hgs
parents: 7
diff changeset
   656
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   657
    platforms, always returns \c false.
hgs
parents: 7
diff changeset
   658
    
hgs
parents: 7
diff changeset
   659
    \sa localisedCollationName(), currentCollation()
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   660
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   661
bool HbLocaleUtil::changeCollation( const QString &collation )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   662
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   663
#if defined(Q_OS_SYMBIAN) 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   664
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   665
    if(mappingList.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   666
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   667
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   668
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   669
    int count = mappingList.count();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   670
    for (int j = 0; j < count; j++)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   671
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   672
        HbLocaleMapping mapping = mappingList.at(j);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   673
        QString name = mapping.collName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   674
        if(name == collation)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   675
        {
34
hgs
parents: 7
diff changeset
   676
            int retVal = -1;
hgs
parents: 7
diff changeset
   677
            QString dllid = mapping.collationDllId;
hgs
parents: 7
diff changeset
   678
            bool ok;
hgs
parents: 7
diff changeset
   679
            int collCode = dllid.toInt(&ok,10);
hgs
parents: 7
diff changeset
   680
            if(!collCode)
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   681
                return false;
34
hgs
parents: 7
diff changeset
   682
            retVal = SysLangUtil::ChangeCollation(collCode);
hgs
parents: 7
diff changeset
   683
            if(retVal != 0)
hgs
parents: 7
diff changeset
   684
                return false;
hgs
parents: 7
diff changeset
   685
            else
hgs
parents: 7
diff changeset
   686
                return true;
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   687
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   688
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   689
    return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   690
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   691
    Q_UNUSED(collation);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   692
    return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   693
#endif    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   694
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   695
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   696
/*!
34
hgs
parents: 7
diff changeset
   697
    
hgs
parents: 7
diff changeset
   698
    Returns the identifier of the current collation. Typically the collation 
hgs
parents: 7
diff changeset
   699
    identifier is an ISO 639 language code, but in some cases, it is a 
hgs
parents: 7
diff changeset
   700
    combination of an ISO 639 language code and an ISO 3166 country code. For 
hgs
parents: 7
diff changeset
   701
    example, for UK English, this returns "en", and for US English, this returns 
hgs
parents: 7
diff changeset
   702
    "en_US".
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   703
34
hgs
parents: 7
diff changeset
   704
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   705
    platforms, always returns an empty QString.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   706
    
34
hgs
parents: 7
diff changeset
   707
    \sa supportedCollations(), localisedCollationName(), changeCollation(), languageRegionMappings()
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   708
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   709
QString HbLocaleUtil::currentCollation()
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   710
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   711
#if defined(Q_OS_SYMBIAN)      
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   712
    if(mappingList.isEmpty())
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   713
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   714
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   715
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   716
    TExtendedLocale dummy;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   717
    dummy.LoadSystemSettings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   718
    TBuf<256> name;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   719
    dummy.GetLocaleDllName(ELocaleCollateSetting,name);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   720
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   721
    QString dllname;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   722
#ifdef QT_NO_UNICODE
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   723
    dllname = QString::fromLocal8Bit(name.Ptr(), name.Length());
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   724
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   725
    dllname = QString::fromUtf16(name.Ptr(), name.Length());
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   726
#endif    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   727
    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   728
    dllname = dllname.right(COLLATION_DLL_PREFIX_POSITION);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   729
    int cnt = mappingList.count();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   730
    for(int i = 0; i < cnt; i++)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   731
    {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   732
        HbLocaleMapping mapping = mappingList.at(i);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   733
        QString dllid = mapping.collationDllId;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   734
        if(dllid == dllname)
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   735
        {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   736
            return mapping.collName;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   737
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   738
    }
7
923ff622b8b9 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 6
diff changeset
   739
#endif    
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   740
    return QString();    
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   741
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   742
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   743
/*!
34
hgs
parents: 7
diff changeset
   744
hgs
parents: 7
diff changeset
   745
    Changes the system language, region and collation as specified by \a 
hgs
parents: 7
diff changeset
   746
    language. The region and collation are selected automatically based on the 
hgs
parents: 7
diff changeset
   747
    specified language.
hgs
parents: 7
diff changeset
   748
hgs
parents: 7
diff changeset
   749
    \param language The language identifier. This must correspond to an 
hgs
parents: 7
diff changeset
   750
    identifier returned by supportedLanguages(), or an 
hgs
parents: 7
diff changeset
   751
    HbLanguageRegionMapping::languageId string.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   752
  
34
hgs
parents: 7
diff changeset
   753
    \return \c true if successful, otherwise \c false.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   754
    
34
hgs
parents: 7
diff changeset
   755
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   756
    platforms, always returns \c false.
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   757
    
34
hgs
parents: 7
diff changeset
   758
    \sa supportedRegions(), supportedCollations(), languageRegionMappings()
hgs
parents: 7
diff changeset
   759
 
6
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   760
*/ 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   761
bool HbLocaleUtil::changeLocale( const QString &language )
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   762
{
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   763
#if defined(Q_OS_SYMBIAN) 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   764
    if(mappingList.isEmpty()) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   765
        readMappings();
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   766
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   767
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   768
    for (int i = 0;  i < mappingList.count(); ++i) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   769
        HbLocaleMapping map = mappingList.at(i);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   770
        if (map.langName == language) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   771
            if (!changeLanguage(map.langName)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   772
                return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   773
            } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   774
            if (!changeRegion(map.regName)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   775
                return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   776
            } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   777
            if (!changeCollation(map.collName)) {
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   778
                return false;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   779
            } 
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   780
            return true;
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   781
        }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   782
    }
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   783
#else
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   784
    Q_UNUSED(language);
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   785
#endif // Q_OS_SYMBIAN
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   786
    return false;   
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   787
}
c3690ec91ef8 Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   788
34
hgs
parents: 7
diff changeset
   789
/*!
hgs
parents: 7
diff changeset
   790
    
hgs
parents: 7
diff changeset
   791
    \struct HbLanguageRegionMapping hblocaleutil.h
hgs
parents: 7
diff changeset
   792
    
hgs
parents: 7
diff changeset
   793
    Defines the data structure for language, region and collation identifier 
hgs
parents: 7
diff changeset
   794
    mappings.
hgs
parents: 7
diff changeset
   795
    
hgs
parents: 7
diff changeset
   796
    \sa HbLocaleUtil::languageRegionMappings()
hgs
parents: 7
diff changeset
   797
  
hgs
parents: 7
diff changeset
   798
*/
hgs
parents: 7
diff changeset
   799
hgs
parents: 7
diff changeset
   800
/*!
hgs
parents: 7
diff changeset
   801
    
hgs
parents: 7
diff changeset
   802
    \var HbLanguageRegionMapping::languageId
hgs
parents: 7
diff changeset
   803
    
hgs
parents: 7
diff changeset
   804
    A language identifier. Typically this is an ISO 639 language code, but in 
hgs
parents: 7
diff changeset
   805
    some cases, it is a combination of an ISO 639 language code and an ISO 3166 
hgs
parents: 7
diff changeset
   806
    country code. For example, for UK English, this returns "en", and for US 
hgs
parents: 7
diff changeset
   807
    English, this returns "en_US".
hgs
parents: 7
diff changeset
   808
  
hgs
parents: 7
diff changeset
   809
*/ 
hgs
parents: 7
diff changeset
   810
hgs
parents: 7
diff changeset
   811
/*!
hgs
parents: 7
diff changeset
   812
    
hgs
parents: 7
diff changeset
   813
    \var HbLanguageRegionMapping::regionId
hgs
parents: 7
diff changeset
   814
    
hgs
parents: 7
diff changeset
   815
    A region identifier. This is a two-letter ISO 3166 code, for example, "GB" 
hgs
parents: 7
diff changeset
   816
    for United Kingdom.
hgs
parents: 7
diff changeset
   817
  
hgs
parents: 7
diff changeset
   818
*/ 
hgs
parents: 7
diff changeset
   819
hgs
parents: 7
diff changeset
   820
/*!
hgs
parents: 7
diff changeset
   821
    
hgs
parents: 7
diff changeset
   822
    \var HbLanguageRegionMapping::collationId
hgs
parents: 7
diff changeset
   823
    
hgs
parents: 7
diff changeset
   824
    A collation identifier. Typically this is an ISO 639 language code, but in 
hgs
parents: 7
diff changeset
   825
    some cases, it is a combination of an ISO 639 language code and an ISO 3166 
hgs
parents: 7
diff changeset
   826
    country code. For example, for UK English, this returns "en", and for US 
hgs
parents: 7
diff changeset
   827
    English, this returns "en_US".
hgs
parents: 7
diff changeset
   828
  
hgs
parents: 7
diff changeset
   829
*/ 
hgs
parents: 7
diff changeset
   830
hgs
parents: 7
diff changeset
   831
/*!
hgs
parents: 7
diff changeset
   832
    
hgs
parents: 7
diff changeset
   833
    Returns a list of language, region and collation identifier mappings. For 
hgs
parents: 7
diff changeset
   834
    example, for UK English, the mapping has "en" for language, "GB" for region 
hgs
parents: 7
diff changeset
   835
    and "en" for collation. For US English, the corresponding values are 
hgs
parents: 7
diff changeset
   836
    "en_US", "US" and "en_US". You can use the optional \a onlySupported 
hgs
parents: 7
diff changeset
   837
    parameter to limit the search only to the languages, regions and collations 
hgs
parents: 7
diff changeset
   838
    supported on the device.
hgs
parents: 7
diff changeset
   839
        
hgs
parents: 7
diff changeset
   840
    If there is a mapping with a language that does not have a corresponding 
hgs
parents: 7
diff changeset
   841
    region, the region is returned as an empty QString. Similarly, if there is a 
hgs
parents: 7
diff changeset
   842
    mapping with a region that does not have a corresponding language and 
hgs
parents: 7
diff changeset
   843
    collation, the language and collation are returned as empty QStrings.
hgs
parents: 7
diff changeset
   844
    
hgs
parents: 7
diff changeset
   845
    \param onlySupported Specify \c true to only return the mappings for 
hgs
parents: 7
diff changeset
   846
    languages, regions and collations that are supported on the device. To 
hgs
parents: 7
diff changeset
   847
    return mappings for all known languages, regions and collations, specify \c 
hgs
parents: 7
diff changeset
   848
    false.
hgs
parents: 7
diff changeset
   849
    
hgs
parents: 7
diff changeset
   850
    For example:
hgs
parents: 7
diff changeset
   851
    \snippet{unittest_hblocaleutil/unittest_hblocaleutil.cpp,2}
hgs
parents: 7
diff changeset
   852
hgs
parents: 7
diff changeset
   853
    \attention Only fully implemented on the Symbian platform. For other 
hgs
parents: 7
diff changeset
   854
    platforms, always returns an empty list.
hgs
parents: 7
diff changeset
   855
    
hgs
parents: 7
diff changeset
   856
    \sa currentLanguage(), currentRegion(), currentCollation()
hgs
parents: 7
diff changeset
   857
  
hgs
parents: 7
diff changeset
   858
*/ 
hgs
parents: 7
diff changeset
   859
QList<HbLanguageRegionMapping> HbLocaleUtil::languageRegionMappings( bool onlySupported )
hgs
parents: 7
diff changeset
   860
{
hgs
parents: 7
diff changeset
   861
    QList<HbLanguageRegionMapping> mps;
hgs
parents: 7
diff changeset
   862
#if defined(Q_OS_SYMBIAN) 
hgs
parents: 7
diff changeset
   863
    if (mappingList.isEmpty()) {
hgs
parents: 7
diff changeset
   864
        readMappings();
hgs
parents: 7
diff changeset
   865
    }
hgs
parents: 7
diff changeset
   866
   
hgs
parents: 7
diff changeset
   867
    QStringList supportedLanguages;
hgs
parents: 7
diff changeset
   868
    QStringList supportedRegions;
hgs
parents: 7
diff changeset
   869
    if (onlySupported) {
hgs
parents: 7
diff changeset
   870
        supportedLanguages = HbLocaleUtil::supportedLanguages();
hgs
parents: 7
diff changeset
   871
        supportedRegions = HbLocaleUtil::supportedRegions();
hgs
parents: 7
diff changeset
   872
    }
hgs
parents: 7
diff changeset
   873
    
hgs
parents: 7
diff changeset
   874
    for (int i = 0;  i < mappingList.count(); ++i) {
hgs
parents: 7
diff changeset
   875
hgs
parents: 7
diff changeset
   876
        HbLocaleMapping map = mappingList.at(i);
hgs
parents: 7
diff changeset
   877
hgs
parents: 7
diff changeset
   878
        HbLanguageRegionMapping mapping;
hgs
parents: 7
diff changeset
   879
        mapping.languageId = map.langName;
hgs
parents: 7
diff changeset
   880
        mapping.regionId = map.regName;
hgs
parents: 7
diff changeset
   881
        mapping.collationId = map.collName;
hgs
parents: 7
diff changeset
   882
hgs
parents: 7
diff changeset
   883
        if (onlySupported) {
hgs
parents: 7
diff changeset
   884
            bool langSupported = supportedLanguages.contains(map.langName);
hgs
parents: 7
diff changeset
   885
            bool regSupported = supportedRegions.contains(map.regName);
hgs
parents: 7
diff changeset
   886
            if (!langSupported && !regSupported) {
hgs
parents: 7
diff changeset
   887
                continue;
hgs
parents: 7
diff changeset
   888
            }
hgs
parents: 7
diff changeset
   889
            if (!langSupported) {
hgs
parents: 7
diff changeset
   890
                mapping.languageId = "";
hgs
parents: 7
diff changeset
   891
            }
hgs
parents: 7
diff changeset
   892
            if (!regSupported) {
hgs
parents: 7
diff changeset
   893
                mapping.regionId = "";
hgs
parents: 7
diff changeset
   894
            }
hgs
parents: 7
diff changeset
   895
        }
hgs
parents: 7
diff changeset
   896
hgs
parents: 7
diff changeset
   897
        mps.append(mapping);
hgs
parents: 7
diff changeset
   898
hgs
parents: 7
diff changeset
   899
    }
hgs
parents: 7
diff changeset
   900
#else
hgs
parents: 7
diff changeset
   901
    Q_UNUSED(onlySupported);
hgs
parents: 7
diff changeset
   902
#endif // Q_OS_SYMBIAN
hgs
parents: 7
diff changeset
   903
    return mps;
hgs
parents: 7
diff changeset
   904
}
hgs
parents: 7
diff changeset
   905