Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7237 from leibovic/manifest-locales

[Bug 824418] Use localized data from app manifests. r=vingtetun a=bb+
  • Loading branch information...
commit 39d283d94a5c4c68bea73bb0d59a44f10e797eae 2 parents afbf700 + 6e7b53a
@leibovic leibovic authored
View
1  apps/homescreen/index.html
@@ -13,6 +13,7 @@
<!-- Shared code -->
<script type="text/javascript" src="shared/js/l10n.js"></script>
<script type="text/javascript" src="shared/js/l10n_date.js"></script>
+ <script type="text/javascript" defer src="shared/js/manifest_helper.js"></script>
<link rel="stylesheet" type="text/css" href="shared/style_unstable/progress_activity.css">
<link rel="stylesheet" type="text/css" href="shared/style/buttons.css">
View
9 apps/homescreen/js/grid.js
@@ -692,6 +692,8 @@ const GridManager = (function() {
if (entryPoint)
iconsAndNameHolder = manifest.entry_points[entryPoint];
+ iconsAndNameHolder = new ManifestHelper(iconsAndNameHolder);
+
var descriptor = {
bookmarkURL: app.bookmarkURL,
manifestURL: app.manifestURL,
@@ -702,12 +704,7 @@ const GridManager = (function() {
icon: bestMatchingIcon(app, iconsAndNameHolder)
};
if (haveLocale && !app.isBookmark) {
- var locales = iconsAndNameHolder.locales;
- if (locales) {
- var locale = locales[document.documentElement.lang];
- if (locale && locale.name)
- descriptor.localizedName = locale.name;
- }
+ descriptor.localizedName = iconsAndNameHolder.name;
}
// If there's an existing icon for this bookmark/app/entry point already, let
View
2  apps/homescreen/js/homescreen.js
@@ -83,6 +83,8 @@ const Homescreen = (function() {
body = _('remove-body', { name: manifest.name });
confirm.title = _('remove');
} else {
+ // Make sure to get the localized name
+ manifest = new ManifestHelper(manifest);
title = _('delete-title', { name: manifest.name });
body = _('delete-body', { name: manifest.name });
confirm.title = _('delete');
View
9 apps/homescreen/js/page.js
@@ -361,14 +361,7 @@ Icon.prototype = {
if (entryPoint)
iconsAndNameHolder = manifest.entry_points[entryPoint];
- var localizedName = iconsAndNameHolder.name;
- var locales = iconsAndNameHolder.locales;
- if (locales) {
- var locale = locales[document.documentElement.lang];
- if (locale && locale.name) {
- localizedName = locale.name;
- }
- }
+ var localizedName = new ManifestHelper(iconsAndNameHolder).name;
this.label.textContent = localizedName;
if (descriptor.localizedName != localizedName) {
View
1  apps/settings/index.html
@@ -38,6 +38,7 @@
<link rel="resource" type="application/l10n" href="locales/locales.ini"/>
<script type="application/javascript" src="shared/js/l10n.js"></script>
<script type="application/javascript" src="shared/js/l10n_date.js"></script>
+ <script type="application/javascript" defer src="shared/js/manifest_helper.js"></script>
<!-- Specific code -->
<script type="application/javascript" defer src="js/utils.js"></script>
View
13 apps/settings/js/apps.js
@@ -82,7 +82,7 @@ var ApplicationsList = {
var listFragment = document.createDocumentFragment();
this._apps.forEach(function appIterator(app, index) {
var icon = null;
- var manifest = app.manifest ? app.manifest : app.updateManifest;
+ var manifest = new ManifestHelper(app.manifest ? app.manifest : app.updateManifest);
if (manifest.icons &&
Object.keys(manifest.icons).length) {
@@ -151,7 +151,7 @@ var ApplicationsList = {
showAppDetails: function al_showAppDetail(app) {
this._displayedApp = app;
- var manifest = app.manifest ? app.manifest : app.updateManifest;
+ var manifest = new ManifestHelper(app.manifest ? app.manifest : app.updateManifest);
var developer = manifest.developer;
this.detailTitle.textContent = manifest.name;
@@ -277,7 +277,7 @@ var ApplicationsList = {
return;
var _ = navigator.mozL10n.get;
- var name = this._displayedApp.manifest.name;
+ var name = new ManifestHelper(this._displayedApp.manifest).name;
if (confirm(_('uninstallConfirm', {app: name}))) {
this._displayedApp.uninstall();
@@ -315,9 +315,10 @@ var ApplicationsList = {
_sortApps: function al_sortApps() {
this._apps.sort(function alphabeticalSort(app, otherApp) {
- var manifest = app.manifest ? app.manifest : app.updateManifest;
- var otherManifest = otherApp.manifest ?
- otherApp.manifest : otherApp.updateManifest;
+ var manifest = new ManifestHelper(app.manifest ?
+ app.manifest : app.updateManifest);
+ var otherManifest = new ManifestHelper(otherApp.manifest ?
+ otherApp.manifest : otherApp.updateManifest);
return manifest.name > otherManifest.name;
});
}
View
1  apps/system/index.html
@@ -14,6 +14,7 @@
<script defer src="shared/js/notification_helper.js"></script>
<script defer src="shared/js/async_storage.js"></script>
<script defer src="shared/js/mobile_operator.js"></script>
+ <script defer src="shared/js/manifest_helper.js"></script>
<!-- Wrapper -->
<link rel="stylesheet" type="text/css" href="style/wrapper/wrapper.css">
View
18 apps/system/js/app_install_manager.js
@@ -109,13 +109,9 @@ var AppInstallManager = {
this.size.textContent = _('unknown');
}
- // Get localised name or use default
- var name = manifest.name;
- var locales = manifest.locales;
- var lang = navigator.language;
- if (locales && locales[lang] && locales[lang].name)
- name = locales[lang].name;
- var msg = _('install-app', {'name': name});
+ // Wrap manifest to get localized properties
+ manifest = new ManifestHelper(manifest);
+ var msg = _('install-app', {'name': manifest.name});
this.msg.textContent = msg;
if (manifest.developer) {
@@ -157,7 +153,7 @@ var AppInstallManager = {
showInstallSuccess: function ai_showInstallSuccess(app) {
var manifest = app.manifest || app.updateManifest;
- var name = manifest.name;
+ var name = new ManifestHelper(manifest).name;
var _ = navigator.mozL10n.get;
var msg = _('app-install-success', { appName: name });
SystemBanner.show(msg);
@@ -174,7 +170,7 @@ var AppInstallManager = {
var app = evt.application;
var _ = navigator.mozL10n.get;
var manifest = app.manifest || app.updateManifest;
- var name = manifest.name;
+ var name = new ManifestHelper(manifest).name;
var errorName = app.downloadError.name;
@@ -260,7 +256,7 @@ var AppInstallManager = {
var _ = navigator.mozL10n.get;
var message = _('downloadingAppMessage', {
- appName: manifest.name
+ appName: new ManifestHelper(manifest).name
});
newNode.querySelector('.message').textContent = message;
@@ -404,7 +400,7 @@ var AppInstallManager = {
var title = dialog.querySelector('h1');
title.textContent = navigator.mozL10n.get('stopDownloading', {
- app: manifest.name
+ app: new ManifestHelper(manifest).name
});
dialog.classList.add('visible');
View
2  apps/system/js/updatable.js
@@ -16,7 +16,7 @@ function AppUpdatable(app) {
this._mgmt = navigator.mozApps.mgmt;
this.app = app;
- this.name = app.manifest.name;
+ this.name = new ManifestHelper(app.manifest).name;
this.size = app.updateManifest ? app.updateManifest.size : null;
app.ondownloadavailable = this.availableCallBack.bind(this);
}
View
29 apps/system/js/window_manager.js
@@ -1257,12 +1257,7 @@ var WindowManager = (function() {
return;
var manifest = app.manifest;
- var name = manifest.name;
- if (manifest.locales &&
- manifest.locales[document.documentElement.lang] &&
- manifest.locales[document.documentElement.lang].name) {
- name = manifest.locales[document.documentElement.lang].name;
- }
+ var name = new ManifestHelper(manifest).name;
var origin = app.origin;
// Check if it's a virtual app from a entry point.
@@ -1285,13 +1280,7 @@ var WindowManager = (function() {
if (path.indexOf('/' + ep) == 0 &&
(currentEp.launch_path == path)) {
origin = origin + currentEp.launch_path;
- var lang = document.documentElement.lang;
- if (currentEp.locales && currentEp.locales[lang] &&
- currentEp.locales[lang].name) {
- name = currentEp.locales[lang].name;
- } else {
- name = currentEp.name;
- }
+ name = new ManifestHelper(currentEp).name;
}
}
}
@@ -1496,21 +1485,11 @@ var WindowManager = (function() {
if (!manifest)
return '';
- var lang = document.documentElement.lang;
if (manifest.entry_points && manifest.type == 'certified') {
var entryPoint = manifest.entry_points[origin.split('/')[3]];
- if (entryPoint.locales && entryPoint.locales[lang] &&
- entryPoint.locales[lang].name) {
- return entryPoint.locales[lang].name;
- } else {
- return entryPoint.name;
- }
- } else if (manifest.locales && manifest.locales[lang] &&
- manifest.locales[lang].name) {
- return manifest.locales[lang].name;
- } else {
- return manifest.name;
+ return new ManifestHelper(entryPoint).name;
}
+ return new ManifestHelper(manifest).name;
}
// Deal with crashed apps
View
26 shared/js/manifest_helper.js
@@ -0,0 +1,26 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+/**
+ * Helper object to access manifest information with locale support.
+ */
+
+var ManifestHelper = function(manifest) {
+ var localeRoot = manifest;
+ var locales = manifest.locales;
+
+ if (locales) {
+ var lang = document.documentElement.lang;
+
+ // If there is a manifest entry for the curret locale, use it, otherwise
+ // fallback on the default manifest.
+ localeRoot = locales[lang] || locales[lang.split('-')[0]] || manifest;
+ }
+
+ // Bind the localized property values.
+ for (var prop in manifest) {
+ this[prop] = localeRoot[prop] || manifest[prop];
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.