зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1340396 - Add window.getAppLocales() for ChromeOrXBL. r=smaug
This commit is contained in:
Родитель
a43a48e31a
Коммит
f877a843fa
|
@ -54,6 +54,7 @@
|
|||
#include "nsNetUtil.h"
|
||||
#include "nsVariant.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "mozilla/intl/LocaleService.h"
|
||||
|
||||
// Helper Classes
|
||||
#include "nsJSUtils.h"
|
||||
|
@ -14917,6 +14918,17 @@ nsGlobalWindow::GetPaintWorklet(ErrorResult& aRv)
|
|||
return mPaintWorklet;
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::GetAppLocales(nsTArray<nsString>& aLocales)
|
||||
{
|
||||
nsTArray<nsCString> appLocales;
|
||||
mozilla::intl::LocaleService::GetInstance()->GetAppLocales(appLocales);
|
||||
|
||||
for (uint32_t i = 0; i < appLocales.Length(); i++) {
|
||||
aLocales.AppendElement(NS_ConvertUTF8toUTF16(appLocales[i]));
|
||||
}
|
||||
}
|
||||
|
||||
template class nsPIDOMWindow<mozIDOMWindowProxy>;
|
||||
template class nsPIDOMWindow<mozIDOMWindow>;
|
||||
template class nsPIDOMWindow<nsISupports>;
|
||||
|
|
|
@ -947,6 +947,9 @@ public:
|
|||
mozilla::dom::Worklet*
|
||||
GetPaintWorklet(mozilla::ErrorResult& aRv);
|
||||
|
||||
void
|
||||
GetAppLocales(nsTArray<nsString>& aLocales);
|
||||
|
||||
protected:
|
||||
bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
|
||||
nsIPrincipal& aSubjectPrincipal,
|
||||
|
|
|
@ -87,3 +87,4 @@ skip-if = os != 'win'
|
|||
[test_subscript_bindings.xul]
|
||||
[test_xray_event_constructor.xul]
|
||||
[test_clipboard_events_chrome.html]
|
||||
[test_window_getAppLocales.html]
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1337234
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1337234</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1337234">Mozilla Bug 1337234</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
<script>
|
||||
|
||||
let appLocales = window.getAppLocales();
|
||||
ok(appLocales.length > 0, "getAppLocales returns at least one locale.");
|
||||
is(appLocales[0], "en-US", "The first app locale should be en-US.");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -519,3 +519,18 @@ callback IdleRequestCallback = void (IdleDeadline deadline);
|
|||
partial interface Window {
|
||||
[ChromeOnly] readonly attribute boolean isSecureContextIfOpenerIgnored;
|
||||
};
|
||||
|
||||
partial interface Window {
|
||||
/**
|
||||
* Returns a list of locales that the application should be localized to.
|
||||
*
|
||||
* The result is a sorted list of valid locale IDs and it should be
|
||||
* used for all APIs that accept list of locales, like ECMA402 and L10n APIs.
|
||||
*
|
||||
* This API always returns at least one locale.
|
||||
*
|
||||
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
|
||||
*/
|
||||
[Func="IsChromeOrXBL"]
|
||||
sequence<DOMString> getAppLocales();
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче