-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add locale methods to String type
- Added locale support to: * String.localeCompare() * String.toLocaleLowerCase() * String.toLocaleUpperCase() Fixes TIMOB-27892
- Loading branch information
1 parent
e4fdd5e
commit 683adaf
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2020 by Axway, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
/* globals OS_ANDROID */ | ||
|
||
if (OS_ANDROID) { | ||
String.prototype.localeCompare = function (compareString, locales, options) { | ||
const collator = new Intl.Collator(locales, options); | ||
return collator.compare(this, compareString); | ||
}; | ||
|
||
String.prototype.toLocaleLowerCase = function (locale) { | ||
return Ti.Locale.makeLowerCase(this, locale); | ||
}; | ||
|
||
String.prototype.toLocaleUpperCase = function (locale) { | ||
return Ti.Locale.makeUpperCase(this, locale); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2018-Present by Axway, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
/* eslint-env mocha */ | ||
|
||
/* eslint no-unused-expressions: "off" */ | ||
'use strict'; | ||
const should = require('./utilities/assertions'); | ||
|
||
describe('String', function () { | ||
it('#localeCompare()', () => { | ||
const string1 = 'réservé'; | ||
const string2 = 'RESERVE'; | ||
should(string1.localeCompare).not.be.undefined(); | ||
should(string1.localeCompare).be.a.Function(); | ||
should(string1.localeCompare(string2)).be.a.Number(); | ||
should(string1.localeCompare(string2)).be.above(0); | ||
should(string1.localeCompare(string2, 'en')).be.above(0); | ||
should(string1.localeCompare(string2, [ 'en' ])).be.above(0); | ||
should(string1.localeCompare(string2, [ 'en', 'de' ])).be.above(0); | ||
should(string1.localeCompare(string2, undefined, { sensitivity: 'base' })).be.eql(0); | ||
should(string1.localeCompare(string2, 'en', { sensitivity: 'base' })).be.eql(0); | ||
should(string1.localeCompare(string2, [ 'en' ], { sensitivity: 'base' })).be.eql(0); | ||
should(string1.localeCompare(string2, [ 'en', 'de' ], { sensitivity: 'base' })).be.eql(0); | ||
}); | ||
|
||
it('#toLocaleLowerCase()', () => { | ||
const text = 'İstanbul'; | ||
should(text.toLocaleLowerCase).not.be.undefined(); | ||
should(text.toLocaleLowerCase).be.a.Function(); | ||
should(text.toLocaleLowerCase()).be.a.String(); | ||
should(text.toLocaleLowerCase('en-US')).be.eql('i̇stanbul'); | ||
should(text.toLocaleLowerCase([ 'en-US' ])).be.eql('i̇stanbul'); | ||
should(text.toLocaleLowerCase([ 'en-US', 'de-DE' ])).be.eql('i̇stanbul'); | ||
should(text.toLocaleLowerCase('tr-TR')).be.eql('istanbul'); | ||
should(text.toLocaleLowerCase([ 'tr-TR' ])).be.eql('istanbul'); | ||
}); | ||
|
||
it('#toLocaleUpperCase()', () => { | ||
const text = 'istanbul'; | ||
should(text.toLocaleUpperCase).not.be.undefined(); | ||
should(text.toLocaleUpperCase).be.a.Function(); | ||
should(text.toLocaleUpperCase()).be.a.String(); | ||
should(text.toLocaleUpperCase('en-US')).be.eql('ISTANBUL'); | ||
should(text.toLocaleUpperCase([ 'en-US' ])).be.eql('ISTANBUL'); | ||
should(text.toLocaleUpperCase([ 'en-US', 'de-DE' ])).be.eql('ISTANBUL'); | ||
should(text.toLocaleUpperCase('tr-TR')).be.eql('İSTANBUL'); | ||
should(text.toLocaleUpperCase([ 'tr-TR' ])).be.eql('İSTANBUL'); | ||
}); | ||
}); |