From 031ffca6f5a4be58e51f86ca209c7c5d034392af Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Tue, 9 Oct 2018 18:20:35 +0200 Subject: [PATCH 01/13] =?UTF-8?q?Add=20method=20to=20get=20system=C2=B4s?= =?UTF-8?q?=20user=20region?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atom/browser/api/atom_api_app.cc | 51 ++++++++++++++++++++++++++++++++ atom/browser/api/atom_api_app.h | 1 + docs/api/app.md | 4 +++ 3 files changed, 56 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index c81a4ed856585..81dd67de1a901 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -60,6 +60,7 @@ #endif #if defined(OS_MACOSX) +#include #include "atom/browser/ui/cocoa/atom_bundle_mover.h" #endif @@ -874,6 +875,55 @@ std::string App::GetLocale() { return g_browser_process->GetApplicationLocale(); } +std::string App::GetRegion() { + std::string region; + +#if defined(OS_WIN) + WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0}; + + if ( + GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_SISO3166CTRYNAME, + (LPWSTR)&locale_name, + sizeof(locale_name) / sizeof(WCHAR)) + || + GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, + LOCALE_SISO3166CTRYNAME, + (LPWSTR)&locale_name, + sizeof(locale_name) / sizeof(WCHAR))) { + char tmp[wcslen(locale_name) * 4]; + WideCharToMultiByte(CP_ACP, 0, locale_name, -1, tmp, sizeof(locale_name), NULL, NULL); + region = tmp; + } +#elif defined(OS_MACOSX) + auto locale = CFLocaleCopyCurrent(); + auto value = CFStringRef(static_cast(CFLocaleGetValue(locale, kCFLocaleCountryCode))); + const CFIndex kCStringSize = 128; + char temporaryCString[kCStringSize]; + bzero(temporaryCString,kCStringSize); + CFStringGetCString(value, temporaryCString, kCStringSize, kCFStringEncodingUTF8); + region = temporaryCString; +#else + std::string locale = setlocale(LC_TIME, NULL); + if (locale.empty()) + locale = setlocale(LC_NUMERIC, NULL); + + if (!locale.empty()) { + std::string::size_type rpos = locale.rfind('.'); + if (rpos != std::string::npos) + locale = locale.substr(0, locale.rfind('.')); + + rpos = locale.rfind('_'); + if (rpos != std::string::npos && region.size() > rpos) + region = locale.substr(rpos + 1, 2); + } +#endif + if (!region.empty() && region.size() == 2) + return region; + + return ""; +} + void App::OnSecondInstance(const base::CommandLine::StringVector& cmd, const base::FilePath& cwd) { Emit("second-instance", cmd, cwd); @@ -1288,6 +1338,7 @@ void App::BuildPrototype(v8::Isolate* isolate, .SetMethod("getPath", &App::GetPath) .SetMethod("setDesktopName", &App::SetDesktopName) .SetMethod("getLocale", &App::GetLocale) + .SetMethod("getRegion", &App::GetRegion) #if defined(USE_NSS_CERTS) .SetMethod("importCertificate", &App::ImportCertificate) #endif diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 2e775a6c00448..ce6d26d8a87d1 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -182,6 +182,7 @@ class App : public AtomBrowserClient::Delegate, void SetDesktopName(const std::string& desktop_name); std::string GetLocale(); + std::string GetRegion(); void OnSecondInstance(const base::CommandLine::StringVector& cmd, const base::FilePath& cwd); bool HasSingleInstanceLock() const; diff --git a/docs/api/app.md b/docs/api/app.md index e4ac418a7cf5b..cc9345adebba9 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -580,6 +580,10 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. +### `app.getRegion()` _macOS_ _Linux_ _Windows_ +Returns `String` - User operating system region in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from OS apis. +**Note:** When unable to detect region, it returns empty string. + ### `app.addRecentDocument(path)` _macOS_ _Windows_ * `path` String From 72cff16f1c9acfb876acd3051c61428e3139ada2 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Wed, 10 Oct 2018 11:02:07 +0200 Subject: [PATCH 02/13] Fix linter --- atom/browser/api/atom_api_app.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index d776481fac6b6..fcf58b06a7222 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -881,27 +881,26 @@ std::string App::GetRegion() { #if defined(OS_WIN) WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0}; - if ( - GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, - LOCALE_SISO3166CTRYNAME, + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, (LPWSTR)&locale_name, - sizeof(locale_name) / sizeof(WCHAR)) - || - GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, - LOCALE_SISO3166CTRYNAME, + sizeof(locale_name) / sizeof(WCHAR)) || + GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, (LPWSTR)&locale_name, sizeof(locale_name) / sizeof(WCHAR))) { - char tmp[wcslen(locale_name) * 4]; - WideCharToMultiByte(CP_ACP, 0, locale_name, -1, tmp, sizeof(locale_name), NULL, NULL); + char tmp[LOCALE_NAME_MAX_LENGTH * 4]; + WideCharToMultiByte(CP_ACP, 0, locale_name, -1, tmp, sizeof(locale_name), + NULL, NULL); region = tmp; } #elif defined(OS_MACOSX) auto locale = CFLocaleCopyCurrent(); - auto value = CFStringRef(static_cast(CFLocaleGetValue(locale, kCFLocaleCountryCode))); + auto value = CFStringRef( + static_cast(CFLocaleGetValue(locale, kCFLocaleCountryCode))); const CFIndex kCStringSize = 128; char temporaryCString[kCStringSize]; - bzero(temporaryCString,kCStringSize); - CFStringGetCString(value, temporaryCString, kCStringSize, kCFStringEncodingUTF8); + bzero(temporaryCString, kCStringSize); + CFStringGetCString(value, temporaryCString, kCStringSize, + kCFStringEncodingUTF8); region = temporaryCString; #else std::string locale = setlocale(LC_TIME, NULL); From 6db9f191f4c76320958df81ef427e9ddefc4d884 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Wed, 10 Oct 2018 14:23:20 +0200 Subject: [PATCH 03/13] Remove auto types --- atom/browser/api/atom_api_app.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index fcf58b06a7222..df2070088b476 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -893,8 +893,8 @@ std::string App::GetRegion() { region = tmp; } #elif defined(OS_MACOSX) - auto locale = CFLocaleCopyCurrent(); - auto value = CFStringRef( + CFLocaleRef locale = CFLocaleCopyCurrent(); + CFStringRef value = CFStringRef( static_cast(CFLocaleGetValue(locale, kCFLocaleCountryCode))); const CFIndex kCStringSize = 128; char temporaryCString[kCStringSize]; From 7e0eeda0618136ea4fdbd2e33335990265f702b5 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Thu, 11 Oct 2018 15:57:59 +0200 Subject: [PATCH 04/13] Improved detection for POSIX --- atom/browser/api/atom_api_app.cc | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index df2070088b476..29122817bc270 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -877,7 +877,6 @@ std::string App::GetLocale() { std::string App::GetRegion() { std::string region; - #if defined(OS_WIN) WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0}; @@ -886,12 +885,8 @@ std::string App::GetRegion() { sizeof(locale_name) / sizeof(WCHAR)) || GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, (LPWSTR)&locale_name, - sizeof(locale_name) / sizeof(WCHAR))) { - char tmp[LOCALE_NAME_MAX_LENGTH * 4]; - WideCharToMultiByte(CP_ACP, 0, locale_name, -1, tmp, sizeof(locale_name), - NULL, NULL); - region = tmp; - } + sizeof(locale_name) / sizeof(WCHAR))) + base::WideToUTF8(locale_name, wcslen(locale_name), ®ion); #elif defined(OS_MACOSX) CFLocaleRef locale = CFLocaleCopyCurrent(); CFStringRef value = CFStringRef( @@ -903,24 +898,25 @@ std::string App::GetRegion() { kCFStringEncodingUTF8); region = temporaryCString; #else - std::string locale = setlocale(LC_TIME, NULL); - if (locale.empty()) - locale = setlocale(LC_NUMERIC, NULL); + const char* locale_ptr = setlocale(LC_TIME, NULL); + if (locale_ptr == NULL) + locale_ptr = setlocale(LC_NUMERIC, NULL); - if (!locale.empty()) { + if (locale_ptr) { + std::string locale = locale_ptr; std::string::size_type rpos = locale.rfind('.'); if (rpos != std::string::npos) - locale = locale.substr(0, locale.rfind('.')); + locale = locale.substr(0, rpos); rpos = locale.rfind('_'); - if (rpos != std::string::npos && region.size() > rpos) + if (rpos != std::string::npos && rpos + 1 < locale.size()) region = locale.substr(rpos + 1, 2); } #endif - if (!region.empty() && region.size() == 2) + if (region.size() == 2) return region; - return ""; + return std::string(); } void App::OnSecondInstance(const base::CommandLine::StringVector& cmd, From 843379fd1067ee05dc75f7aaf70bd46b076b3e52 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Fri, 12 Oct 2018 18:34:13 +0200 Subject: [PATCH 05/13] Change name, add specs, minor fixes --- atom/browser/api/atom_api_app.cc | 20 +++++++------------- atom/browser/api/atom_api_app.h | 2 +- docs/api/app.md | 5 +++-- spec/api-app-spec.js | 6 ++++++ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 29122817bc270..16409b1631e56 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -875,7 +875,7 @@ std::string App::GetLocale() { return g_browser_process->GetApplicationLocale(); } -std::string App::GetRegion() { +std::string App::GetLocaleCountryCode() { std::string region; #if defined(OS_WIN) WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0}; @@ -892,8 +892,7 @@ std::string App::GetRegion() { CFStringRef value = CFStringRef( static_cast(CFLocaleGetValue(locale, kCFLocaleCountryCode))); const CFIndex kCStringSize = 128; - char temporaryCString[kCStringSize]; - bzero(temporaryCString, kCStringSize); + char temporaryCString[kCStringSize] = {0}; CFStringGetCString(value, temporaryCString, kCStringSize, kCFStringEncodingUTF8); region = temporaryCString; @@ -901,22 +900,17 @@ std::string App::GetRegion() { const char* locale_ptr = setlocale(LC_TIME, NULL); if (locale_ptr == NULL) locale_ptr = setlocale(LC_NUMERIC, NULL); - if (locale_ptr) { std::string locale = locale_ptr; - std::string::size_type rpos = locale.rfind('.'); + std::string::size_type rpos = locale.find('.'); if (rpos != std::string::npos) locale = locale.substr(0, rpos); - - rpos = locale.rfind('_'); + rpos = locale.find('_'); if (rpos != std::string::npos && rpos + 1 < locale.size()) - region = locale.substr(rpos + 1, 2); + region = locale.substr(rpos + 1); } #endif - if (region.size() == 2) - return region; - - return std::string(); + return region.size() == 2 ? region : std::string(); } void App::OnSecondInstance(const base::CommandLine::StringVector& cmd, @@ -1344,8 +1338,8 @@ void App::BuildPrototype(v8::Isolate* isolate, .SetMethod("setPath", &App::SetPath) .SetMethod("getPath", &App::GetPath) .SetMethod("setDesktopName", &App::SetDesktopName) - .SetMethod("getLocale", &App::GetLocale) .SetMethod("getRegion", &App::GetRegion) + .SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode) #if defined(USE_NSS_CERTS) .SetMethod("importCertificate", &App::ImportCertificate) #endif diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 2e346af1b706e..25488cefc9233 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -182,7 +182,7 @@ class App : public AtomBrowserClient::Delegate, void SetDesktopName(const std::string& desktop_name); std::string GetLocale(); - std::string GetRegion(); + std::string GetLocaleCountryCode(); void OnSecondInstance(const base::CommandLine::StringVector& cmd, const base::FilePath& cwd); bool HasSingleInstanceLock() const; diff --git a/docs/api/app.md b/docs/api/app.md index 129d858f82e6d..20517c42a5b75 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -580,8 +580,9 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. -### `app.getRegion()` _macOS_ _Linux_ _Windows_ -Returns `String` - User operating system region in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from OS apis. +### `app.GetLocaleCountryCode()` +Returns `String` - User operating system´s region in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. + **Note:** When unable to detect region, it returns empty string. ### `app.addRecentDocument(path)` _macOS_ _Windows_ diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index caa3ae27e714a..c582720b64da8 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -122,6 +122,12 @@ describe('app module', () => { }) }) + describe('app.getLocaleCountryCode()', () => { + it('should be empty or have length of two', () => { + expect(app.getLocaleCountryCode()).to.have.lengthOf.oneOf([0, 2]) + }) + }) + describe('app.isPackaged', () => { it('should be false durings tests', () => { expect(app.isPackaged).to.be.false() From 75b5ae5a47db5065a3ab135f52f554fa8f3ce42a Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Tue, 16 Oct 2018 09:58:32 +0200 Subject: [PATCH 06/13] Remove left overs --- atom/browser/api/atom_api_app.cc | 2 +- docs/api/app.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 16409b1631e56..d1d7fddb43b24 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -1338,7 +1338,7 @@ void App::BuildPrototype(v8::Isolate* isolate, .SetMethod("setPath", &App::SetPath) .SetMethod("getPath", &App::GetPath) .SetMethod("setDesktopName", &App::SetDesktopName) - .SetMethod("getRegion", &App::GetRegion) + .SetMethod("getLocale", &App::GetLocale) .SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode) #if defined(USE_NSS_CERTS) .SetMethod("importCertificate", &App::ImportCertificate) diff --git a/docs/api/app.md b/docs/api/app.md index 20517c42a5b75..331cc573327dc 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -581,9 +581,9 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. ### `app.GetLocaleCountryCode()` -Returns `String` - User operating system´s region in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. +Returns `String` - User operating system´s locale country code in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. -**Note:** When unable to detect region, it returns empty string. +**Note:** When unable to detect locale country code, it returns empty string. ### `app.addRecentDocument(path)` _macOS_ _Windows_ From 95441a01a8e342cd35697109f9778663ecbccb93 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Wed, 17 Oct 2018 15:48:49 +0200 Subject: [PATCH 07/13] Fix locale test --- docs/api/app.md | 2 +- spec/api-app-spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 331cc573327dc..db944aeb5d1aa 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -580,7 +580,7 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. -### `app.GetLocaleCountryCode()` +### `app.getLocaleCountryCode()` Returns `String` - User operating system´s locale country code in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. **Note:** When unable to detect locale country code, it returns empty string. diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index c582720b64da8..4f464f6755294 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -124,7 +124,7 @@ describe('app module', () => { describe('app.getLocaleCountryCode()', () => { it('should be empty or have length of two', () => { - expect(app.getLocaleCountryCode()).to.have.lengthOf.oneOf([0, 2]) + expect(app.getLocaleCountryCode()).to.have.lengthOf(2) }) }) From 52443674bc48024e96f14e4b4b16ac69e318859d Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Mon, 22 Oct 2018 16:47:48 +0200 Subject: [PATCH 08/13] Fix Linux test --- spec/api-app-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 4f464f6755294..3d9b67acc1f78 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -124,7 +124,7 @@ describe('app module', () => { describe('app.getLocaleCountryCode()', () => { it('should be empty or have length of two', () => { - expect(app.getLocaleCountryCode()).to.have.lengthOf(2) + expect(app.getLocaleCountryCode().length).to.be.oneOf([0, 2]) }) }) From e8921ee813109cc41503e882e6e281af13331a99 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Mon, 5 Nov 2018 15:45:46 +0100 Subject: [PATCH 09/13] Coding style fixes --- atom/browser/api/atom_api_app.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 93a4af4ddeb38..c1ffb488e1c6b 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -893,8 +893,9 @@ std::string App::GetLocaleCountryCode() { sizeof(locale_name) / sizeof(WCHAR)) || GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, (LPWSTR)&locale_name, - sizeof(locale_name) / sizeof(WCHAR))) + sizeof(locale_name) / sizeof(WCHAR))) { base::WideToUTF8(locale_name, wcslen(locale_name), ®ion); + } #elif defined(OS_MACOSX) CFLocaleRef locale = CFLocaleCopyCurrent(); CFStringRef value = CFStringRef( @@ -906,7 +907,7 @@ std::string App::GetLocaleCountryCode() { region = temporaryCString; #else const char* locale_ptr = setlocale(LC_TIME, NULL); - if (locale_ptr == NULL) + if (!locale_ptr) locale_ptr = setlocale(LC_NUMERIC, NULL); if (locale_ptr) { std::string locale = locale_ptr; From 53576850af46ef885366ba8090dcd2e3ddf12adc Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Tue, 6 Nov 2018 11:05:28 +0100 Subject: [PATCH 10/13] Fix docs --- docs/api/app.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/app.md b/docs/api/app.md index 8a0e9a5a6b5b5..4efdcfc768a09 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -604,7 +604,7 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. ### `app.getLocaleCountryCode()` -Returns `String` - User operating system´s locale country code in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. +Returns `string` - User operating system´s locale country code in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. **Note:** When unable to detect locale country code, it returns empty string. From 914ad31438c0f4e705ba648586cfb358360406ab Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Thu, 8 Nov 2018 16:04:41 +0100 Subject: [PATCH 11/13] Add test excaption for Linux --- spec/api-app-spec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index c4b8e4b7d4670..22d1ee41ea875 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -124,7 +124,12 @@ describe('app module', () => { describe('app.getLocaleCountryCode()', () => { it('should be empty or have length of two', () => { - expect(app.getLocaleCountryCode().length).to.be.oneOf([0, 2]) + let expectedLength = 2; + if (isCi && process.platform === 'linux') { + // Linux CI machines have no locale. + expectedLength = 0 + } + expect(app.getLocaleCountryCode()).to.be.a('string').and.have.lengthOf(expectedLength) }) }) From bdc3561d0c319140458699127efafe6116412b95 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Thu, 8 Nov 2018 16:38:28 +0100 Subject: [PATCH 12/13] fix spelling --- spec/api-app-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 22d1ee41ea875..2861eee125cd0 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -125,7 +125,7 @@ describe('app module', () => { describe('app.getLocaleCountryCode()', () => { it('should be empty or have length of two', () => { let expectedLength = 2; - if (isCi && process.platform === 'linux') { + if (isCI && process.platform === 'linux') { // Linux CI machines have no locale. expectedLength = 0 } From 0ba680276f5c80560eb61469f61d1428761d8431 Mon Sep 17 00:00:00 2001 From: Ondrej Zaruba Date: Fri, 9 Nov 2018 09:01:21 +0100 Subject: [PATCH 13/13] Polishing --- docs/api/app.md | 2 +- spec/api-app-spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 4efdcfc768a09..ac697d05a3011 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -604,7 +604,7 @@ To set the locale, you'll want to use a command line switch at app startup, whic **Note:** On Windows you have to call it after the `ready` events gets emitted. ### `app.getLocaleCountryCode()` -Returns `string` - User operating system´s locale country code in ISO3166 [here](https://www.iso.org/iso-3166-country-codes.html). The value is taken from native OS APIs. +Returns `string` - User operating system's locale two-letter [ISO 3166](https://www.iso.org/iso-3166-country-codes.html) country code. The value is taken from native OS APIs. **Note:** When unable to detect locale country code, it returns empty string. diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 2861eee125cd0..8675e8a7a2c66 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -124,7 +124,7 @@ describe('app module', () => { describe('app.getLocaleCountryCode()', () => { it('should be empty or have length of two', () => { - let expectedLength = 2; + let expectedLength = 2 if (isCI && process.platform === 'linux') { // Linux CI machines have no locale. expectedLength = 0