Skip to content

Commit ec7ea30

Browse files
committed
Merge pull request electron#2800 from seanchas116/app-getlocale
App app.getLocale() API to get application locale
2 parents 3f881e8 + 7b75b29 commit ec7ea30

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

atom/browser/api/atom_api_app.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "native_mate/dictionary.h"
3131
#include "native_mate/object_template_builder.h"
3232
#include "net/ssl/ssl_cert_request_info.h"
33+
#include "ui/base/l10n/l10n_util.h"
3334

3435
#if defined(OS_WIN)
3536
#include "base/strings/utf_string_conversions.h"
@@ -248,6 +249,10 @@ void App::SetAppUserModelId(const std::string& app_id) {
248249
#endif
249250
}
250251

252+
std::string App::GetLocale() {
253+
return l10n_util::GetApplicationLocale("");
254+
}
255+
251256
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
252257
if (default_session_.IsEmpty())
253258
return v8::Null(isolate);
@@ -278,6 +283,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
278283
.SetMethod("getPath", &App::GetPath)
279284
.SetMethod("setDesktopName", &App::SetDesktopName)
280285
.SetMethod("setAppUserModelId", &App::SetAppUserModelId)
286+
.SetMethod("getLocale", &App::GetLocale)
281287
.SetProperty("defaultSession", &App::DefaultSession);
282288
}
283289

atom/browser/api/atom_api_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class App : public mate::EventEmitter,
6565

6666
void SetDesktopName(const std::string& desktop_name);
6767
void SetAppUserModelId(const std::string& app_id);
68+
std::string GetLocale();
6869
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
6970

7071
v8::Global<v8::Value> default_session_;

docs/api/app.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ to the npm modules spec. You should usually also specify a `productName`
239239
field, which is your application's full capitalized name, and which will be
240240
preferred over `name` by Electron.
241241

242+
### `app.getLocale()`
243+
244+
Returns the current application locale.
245+
242246
### `app.resolveProxy(url, callback)`
243247

244248
* `url` URL

spec/api-app-spec.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe 'app module', ->
2626
assert.equal app.getName(), 'test-name'
2727
app.setName 'Electron Test'
2828

29+
describe 'app.getLocale()', ->
30+
it 'should not be empty', ->
31+
assert.notEqual app.getLocale(), ''
32+
2933
describe 'BrowserWindow events', ->
3034
w = null
3135
afterEach ->

0 commit comments

Comments
 (0)