Skip to content

Commit

Permalink
Merge pull request #26 from pec1985/timob-8583
Browse files Browse the repository at this point in the history
TIMOB-8583: Implemented Ti.Locale module and L()
  • Loading branch information
Russ McMahon committed Mar 19, 2013
2 parents 1cdfb6c + 4af980e commit 18b949d
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 6 deletions.
11 changes: 11 additions & 0 deletions build_templates/blackberry/blackberryndk.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def package(self, package, appFile, projectName, type, debugToken, isUnitTest =
# Copy all needed resources to assets
assetsDir = os.path.join(buildDir, 'assets')
resourcesDir = os.path.join(projectDir, 'Resources')
i18n = os.path.join(projectDir, 'i18n')
i18nAssetsDir = os.path.join(assetsDir, 'i18n')
blackberryResourcesDir = os.path.join(resourcesDir, 'blackberry')
if os.path.exists(assetsDir):
shutil.rmtree(assetsDir)
Expand All @@ -259,6 +261,15 @@ def package(self, package, appFile, projectName, type, debugToken, isUnitTest =
else:
shutil.copy2(fullEntry, os.path.join(assetsDir, entry))

# Copy the i18n folder to assets
if os.path.exists(i18n):
for entry in os.listdir(i18n):
fullEntry = os.path.join(i18n, entry)
if os.path.isdir(fullEntry):
shutil.copytree(fullEntry, os.path.join(i18nAssetsDir, entry))
else:
shutil.copy2(fullEntry, os.path.join(i18nAssetsDir, entry))

# Copy application properties file into assets.
shutil.copy(os.path.join(buildDir, 'app_properties.ini'), assetsDir)

Expand Down
2 changes: 1 addition & 1 deletion build_templates/blackberry/tibbapp/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LDFLAGS+=-Wl,-z,relro -Wl,-z,now $(if $(filter g so shared,$(VARIANTS)),,-pie)
LIBS+=tibb v8 socket bps

# Extra .so required
LDFLAGS+=-lbbcascades -lbbdevice -lbbsystem -lQtCore -lQtDeclarative -lQtGui -lQtMultimedia -lQtNetwork -lm -lbb
LDFLAGS+=-lbbcascades -lbbdevice -lbbsystem -lQtCore -lQtDeclarative -lQtGui -lQtMultimedia -lQtNetwork -lm -lbb -lbbdata
LDFLAGS+=-lQtSql -lQtSvg -lQtTest -lQtXml -lsqlite3 -lQtLocationSubset -lbbcascadesmaps -lGLESv1_CM -lOpenAL -lalut -lasound -lbbmultimedia

include $(MKFILES_ROOT)/qmacros.mk
Expand Down
6 changes: 6 additions & 0 deletions src/tibb/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/tibb/include}&quot;"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb/data"/>
</option>
<option id="com.qnx.qcc.option.compiler.defines.1265970181" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_REENTRANT"/>
Expand All @@ -57,6 +58,7 @@
<option id="com.qnx.qcc.option.assembler.includePath.2003111605" name="Include Directories (-I)" superClass="com.qnx.qcc.option.assembler.includePath" valueType="includePath">
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb/data"/>
</option>
<inputType id="com.qnx.qcc.inputType.assembler.1271507818" superClass="com.qnx.qcc.inputType.assembler"/>
</tool>
Expand Down Expand Up @@ -102,6 +104,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/tibb/include}&quot;"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb/data"/>
</option>
<option id="com.qnx.qcc.option.compiler.defines.329860137" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_REENTRANT"/>
Expand Down Expand Up @@ -162,6 +165,7 @@
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/freetype2"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/../target-override/usr/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/tibb/include}&quot;"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb/data"/>
</option>
<option id="com.qnx.qcc.option.compiler.defines.940981227" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_REENTRANT"/>
Expand Down Expand Up @@ -226,6 +230,7 @@
<listOptionValue builtIn="false" value="&quot;${QNX_TARGET}/usr/include/qt4/cpp&quot;"/>
<listOptionValue builtIn="false" value="&quot;${QNX_TARGET}/usr/include/qt4/cpp/c&quot;"/>
<listOptionValue builtIn="false" value="&quot;${QNX_TARGET}/usr/include/qt4/cpp/embedded&quot;"/>
<listOptionValue builtIn="false" value="${QNX_TARGET}/usr/include/bb/data"/>
</option>
<option id="com.qnx.qcc.option.compiler.defines.1807513299" name="Defines (-D)" superClass="com.qnx.qcc.option.compiler.defines" valueType="definedSymbols">
<listOptionValue builtIn="false" value="_REENTRANT"/>
Expand All @@ -243,6 +248,7 @@
<tool id="com.qnx.qcc.tool.assembler.361548406" name="QCC Assembler" superClass="com.qnx.qcc.tool.assembler">
<option id="com.qnx.qcc.option.assembler.includePath.344240156" name="Include Directories (-I)" superClass="com.qnx.qcc.option.assembler.includePath" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${QNX_TARGET}/usr/include/qt4&quot;"/>
<listOptionValue builtIn="false" value="{QNX_TARGET}/usr/include/bb/data"/>
</option>
<inputType id="com.qnx.qcc.inputType.assembler.537373931" superClass="com.qnx.qcc.inputType.assembler"/>
</tool>
Expand Down
72 changes: 72 additions & 0 deletions src/tibb/LocaleParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#include "LocaleParser.h"

static LocaleParser* _instance;

LocaleParser::LocaleParser() {
setLocale(QLocale().name());
}

LocaleParser::~LocaleParser() {

}

QString LocaleParser::getString(QString value1, QString value2)
{
if(stringsMap_.contains(value1))
return stringsMap_.value(value1);

if(value2 != "undefined")
return value2;

return value1;
}

QString LocaleParser::getLocale() {
return locale_;
}

QString LocaleParser::getLocaleLanguage() {
return localeLanguage_;
}

QString LocaleParser::getLocaleCountry() {
return localeCountry_;
}

void LocaleParser::setLocale(QString value)
{
stringsMap_.empty();
localeLanguage_ = QString(value.left(2).toLower());
localeCountry_ = QString(value.right(2).toUpper());
locale_ = value;
QString localeFile = QString("app/native/assets/i18n/");
localeFile.append(localeLanguage_);
localeFile.append("/strings.xml");

bb::data::XmlDataAccess xda;
QVariant xml = xda.load(localeFile, "resources/string");
if(xda.hasError()) return;
// TODO: Handle error

QList<QVariant> list = xml.toList();
for(int i = 0; i < list.length(); i++) {
QVariant rawItem = list.at(i);
QVariantMap item = rawItem.toMap();
stringsMap_.insert(item.value("name").toString(), item.value(".data").toString());
}

}

LocaleParser *LocaleParser::sharedInstance()
{
if(_instance == NULL)
_instance = new LocaleParser();
return _instance;
}
33 changes: 33 additions & 0 deletions src/tibb/LocaleParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#ifndef LOCALEPARSER_H_
#define LOCALEPARSER_H_

#include <QLocale>
#include <QObject>
#include <QMap>
#include <bb/data/XmlDataAccess>

class LocaleParser {
public:
LocaleParser();
virtual ~LocaleParser();
static LocaleParser *sharedInstance();
QString getString(QString value1, QString value2);
QString getLocaleLanguage();
QString getLocaleCountry();
QString getLocale();
void setLocale(QString value);
private:
QMap<QString, QString> stringsMap_;
QString localeLanguage_;
QString localeCountry_;
QString locale_;
};

#endif /* LOCALEPARSER_H_ */
90 changes: 90 additions & 0 deletions src/tibb/TiLocaleObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#include "TiLocaleObject.h"
#include "TiGenericFunctionObject.h"
#include <bb/data/XmlDataAccess>

TiLocaleObject::TiLocaleObject()
: TiProxy("Locale")
{
}

TiLocaleObject::~TiLocaleObject()
{
}

void TiLocaleObject::addObjectToParent(TiObject* parent)
{
TiLocaleObject* obj = new TiLocaleObject;
parent->addMember(obj);
}

void TiLocaleObject::onCreateStaticMembers()
{
TiProxy::onCreateStaticMembers();
TiGenericFunctionObject::addGenericFunctionToParent(this, "getString", this, _getString);

TiGenericFunctionObject::addGenericFunctionToParent(this, "getCurrentLanguage", this, _getCurrentLanguage);
TiGenericFunctionObject::addGenericFunctionToParent(this, "getCurrentCountry", this, _getCurrentCountry);
TiGenericFunctionObject::addGenericFunctionToParent(this, "getCurrentLocale", this, _getCurrentLocale);

ADD_STATIC_TI_VALUE("currentLanguage", TiLocaleObject::_getCurrentLanguage(), this);
ADD_STATIC_TI_VALUE("currentCountry", TiLocaleObject::_getCurrentCountry(), this);
ADD_STATIC_TI_VALUE("currentLocale", TiLocaleObject::_getCurrentLocale(), this);
}

Handle<Value> TiLocaleObject::_getCurrentCountry()
{
QString value = LocaleParser::sharedInstance()->getLocaleCountry();
Handle<String> result = String::New(value.toUtf8());
return result;
}

Handle<Value> TiLocaleObject::_getCurrentLocale()
{
QString value = LocaleParser::sharedInstance()->getLocale();
Handle<String> result = String::New(value.toUtf8());
return result;
}

Handle<Value> TiLocaleObject::_getCurrentLanguage()
{
QString value = LocaleParser::sharedInstance()->getLocaleLanguage();
Handle<String> result = String::New(value.toUtf8());
return result;
}

Handle<Value> TiLocaleObject::_getCurrentCountry(void*, TiObject*, const Arguments& args) {
return TiLocaleObject::_getCurrentCountry();
}
Handle<Value> TiLocaleObject::_getCurrentLocale(void*, TiObject*, const Arguments& args)
{
return TiLocaleObject::_getCurrentLocale();
}
Handle<Value> TiLocaleObject::_getCurrentLanguage(void*, TiObject*, const Arguments& args)
{
return TiLocaleObject::_getCurrentLanguage();
}
Handle<Value> TiLocaleObject::_getString(void*, TiObject*, const Arguments& args)
{
Handle<String> arg1 = Handle<String>::Cast(args[0]);
Handle<String> arg2 = Handle<String>::Cast(args[1]);

String::Utf8Value arg1string(arg1);
String::Utf8Value arg2string(arg2);

QString value1 = QString(*arg1string);
QString value2 = QString(*arg2string);
QString returnedString;

returnedString = LocaleParser::sharedInstance()->getString(value1, value2);

Handle<String> result = String::New(returnedString.toUtf8());
return result;

}
42 changes: 42 additions & 0 deletions src/tibb/TiLocaleObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

#ifndef TILOCALEOBJECT_H_
#define TILOCALEOBJECT_H_

#include "LocaleParser.h"

#include "TiProxy.h"

/*
* TiLocaleObject
*
* Locale module containing stream utility methods.
*/
class TiLocaleObject : public TiProxy
{
public:
static void addObjectToParent(TiObject* parent);
static Handle<Value> _getString(void*, TiObject*, const Arguments& args);

protected:
virtual ~TiLocaleObject();
virtual void onCreateStaticMembers();

private:
TiLocaleObject();
TiLocaleObject(const TiLocaleObject&);
TiLocaleObject& operator=(const TiLocaleObject&);
static Handle<Value> _getCurrentLanguage(void*, TiObject*, const Arguments& args);
static Handle<Value> _getCurrentCountry(void*, TiObject*, const Arguments& args);
static Handle<Value> _getCurrentLocale(void*, TiObject*, const Arguments& args);
static Handle<Value> _getCurrentLanguage();
static Handle<Value> _getCurrentCountry();
static Handle<Value> _getCurrentLocale();
};

#endif /* TILOCALEOBJECT_H_ */
6 changes: 3 additions & 3 deletions src/tibb/TiRootObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "NativeStringInterface.h"
#include "TiGenericFunctionObject.h"
#include "TiLocaleObject.h"
#include "TiLogger.h"
#include "TiMessageStrings.h"
#include "TiTitaniumObject.h"
Expand Down Expand Up @@ -183,10 +184,9 @@ void TiRootObject::createStringMethods()
}

/* Methods defined by Global */
Handle<Value> TiRootObject::_L(void*, TiObject*, const Arguments& args)
Handle<Value> TiRootObject::_L(void* arg1, TiObject* arg2, const Arguments& arg3)
{
// TODO: finish this
return args[0];
return TiLocaleObject::_getString(arg1, arg2, arg3);
}

Handle<Value> TiRootObject::_clearInterval(void*, TiObject*, const Arguments& args)
Expand Down
2 changes: 2 additions & 0 deletions src/tibb/TiTitaniumObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "TiLogger.h"
#include "TiMessageStrings.h"
#include "TiPlatformObject.h"
#include "TiLocaleObject.h"
#include "TiStreamObject.h"
#include "TiUIObject.h"
#include "TiMap.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ void TiTitaniumObject::onCreateStaticMembers()
TiDatabase::addObjectToParent(this, objectFactory_);
TiBufferStreamObject::addObjectToParent(this);
TiStreamObject::addObjectToParent(this);
TiLocaleObject::addObjectToParent(this);
}

bool TiTitaniumObject::canAddMembers() const
Expand Down
2 changes: 1 addition & 1 deletion src/tibb/tibb.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ HEADERS += \
./*.h \
TableView/BasicListItem.h \
TableView/ListItemData.h
LIBS += -lz -lsqlite3 -lQtLocationSubset -lbbcascadesmaps -lGLESv1_CM -lOpenAL -lalut -lasound -lbbmultimedia
LIBS += -lz -lsqlite3 -lQtLocationSubset -lbbcascadesmaps -lGLESv1_CM -lOpenAL -lalut -lasound -lbbmultimedia -lbbdata

device {
CONFIG(release, debug|release) {
Expand Down

0 comments on commit 18b949d

Please sign in to comment.