Skip to content
LocaleHelper.qml 5 KiB
Newer Older
/*
    This file is part of Gabriel's Qt/QML CardBoard Sample (or short GQQCS)

    GQQCS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    GQQCS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

    Updated: 07/08/2015 by: Gabriel F.
*/

import QtQuick 2.4

Item {
    id: root
    visible: false

    property bool         loaded: false
    property string   localeCode: "en_US"
    property string localePrefix: "en"

    onLocalePrefixChanged: {
        console.log("Current language code is "+localeCode+" and language prefix is "+localePrefix)
    }

    property var      localeData: {
                "CTitle":["Configuração\ntoque aqui para iniciar","Configuration\nTouch here to start"],
                "3DGyro":["3D + Giroscópio","3D + Gyroscope"],
                "MonoGyro":["Mono + Giroscópio","Mono + Gyroscope"],
                "3DTouch":["3D + Toque/Gestos","3D + Touch/Gestures"],
                "MonoTouch":["Mono + Toque/Gestos","Mono + Touch/Gestures"],
                "3DDescription":["3D: óculos VR (Cardboard) ou Streaming para TV 3D","3D: Cardboard style VR Glasses or Streaming to 3D TV"],
                "MonoDescription":["Mono: Visão Única","Mono: Single View"],
                "TouchDescription":["Navegação: Toque/arraste para navegar e mantenha o dedo sobre o ícone para ativar conteúdo.","Navigation : Touch/Drag to move and hold your finger on the icon to activate content."],
                "GyroDescription":["Navegação: Gire o celular para navegar e mantenha o cursor sobre um ícone para ativar conteúdo.","Navigation : Rotate the phone to move and maintain the cursor over an icon to activate content."],
                "ViewModeTitle":["toque aqui para alterar modo:","touch here to change mode:"],
                "Description":["Descrição","Description"],
                "Option1Label":["Option 1 PT","Option 1 EN"],
                "Option1Title":["Option 1 Video Title PT","Option 1 Video Title EN"],
                "Option2Label":["Option 2 PT","Option 2 EN"],
                "Option2Title":["Option 2 Video Title PT","Option 2 Video Title EN"],
                "Option3Label":["Option 3 PT","Option 3 EN"],
                "Option3Title":["Option 3 Video Title PT","Option 3 Video Title EN"],
                "Option4Label":["Option 4 PT","Option 4 EN"],
                "Option4Title":["Option 4 Video Title PT","Option 4 Video Title EN"],
                "StartTitle":["Start","Start"],
                "AboutTitle":["About","About"],
                "AboutText":["GQQCS is a great template for building simple Stereo Image e Video Viewers in Qt/QML, use this template to make great apps for mobile.(PT)","GQQCS is a great template for building simple Stereo Image e Video Viewers in Qt/QML, use this template to make great apps for mobile.(EN)"],
                "BackText":["BACK","BACK"],
                "BackTextDetailsG":["olhe para o chão para voltar","look down to return"],
                "BackTextDetailsT":["deslize até a base para voltar","slide down to return"],
                "SobreAppBig":["v1.0 07/2015\n\nUse this great app!","v1.0 07/2015\n\nUse this great app!"],
                "SobreAppGAF":["Aplicação desenvolvida por: Gabriel A. Fernandes\nhttp://www.gabrieldesign.com.br || http://gaf.impa.br\n\nCódigo fonte e licença disponíveis em:\nhttp://git.impa.br/gaf/GQQCS","App developed by: Gabriel A. Fernandes\nhttp://www.gabrieldesign.com.br || http://gaf.impa.br\n\nSource code and license available at:\nhttp://git.impa.br/gaf/GQQCS"]
    }
    property var  availableCodes: ["pt","en"]
    property var  loadCallback: function() {  }

    function loadLocaleData() {
        localeCode = Qt.locale().name
        localePrefix = localeCode.substring(0,2)
        console.log("Current language code is "+localeCode+" and language prefix is "+localePrefix)
        loaded = true
    }

    function getSymbol(symbol) {
        if (!loaded) { loadLocaleData() }

        var prefixIndex = 0
        if (availableCodes.indexOf(localePrefix) >= 0) {
            prefixIndex = availableCodes.indexOf(localePrefix)
        } else {
            prefixIndex = 1
        }

        if (!localeData.hasOwnProperty("Zero")) {
            if (localeData.hasOwnProperty(symbol)) {
                return localeData[symbol][prefixIndex]
            } else {
                console.log("Data available, but cant find symbol "+symbol)
                return "?"+symbol+"?"
            }
        } else {
            console.log("No locale data available...")
            return "!"+symbol+"!"
        }
    }
}