-
Notifications
You must be signed in to change notification settings - Fork 7.6k
fix Issue #8953- "Localizing package metadata in Extension Manager" #8987
Changes from 6 commits
7cf0b40
8d47643
d08d557
fbf682e
dd6d579
019edbb
da86d28
6aa3cea
cb01a98
a7c8238
117b20c
05d802d
8fddc38
c973447
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ | |
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
var Strings = require("strings"), | ||
var _ = require("thirdparty/lodash"), | ||
Strings = require("strings"), | ||
StringUtils = require("utils/StringUtils"), | ||
ExtensionManager = require("extensibility/ExtensionManager"), | ||
registry_utils = require("extensibility/registry_utils"), | ||
|
@@ -211,6 +212,24 @@ define(function (require, exports, module) { | |
context.isCompatible = context.isCompatibleLatest = true; | ||
} | ||
|
||
// Extension metadata might have localized content. If so, overlay (or concatenate) those strings. | ||
var lang = brackets.getLocale(), | ||
shortLang = lang.split("-")[0], | ||
useShortLang = info.metadata.hasOwnProperty(shortLang); | ||
if (useShortLang || info.metadata.hasOwnProperty(lang)) { | ||
var key = useShortLang ? shortLang : lang; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should replace the properties for both the short and the long language. Lets say that for some reason the title and description are in Spanish, so I then provide a title and description for "en", and I also provide just a title for "en-uk". If the language is "en-uk" we could first replace the title and description from "en" (as it is the shortLang) and then replace the title from "en-uk". [shortLang, lang].forEach(function (locale) {
if (info.metadata.hasOwnProperty(locale)) {
_.forEach(info.metadata[locale], function (value, prop) {
// Do the replacement ...
});
}
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh? I hadn't encountered that before, so thanks for the suggestion. I'll add that. |
||
_.forEach(info.metadata[key], function (value, prop) { | ||
if (prop !== "keywords") { | ||
// overlay existing string w/ localized string | ||
info.metadata[prop] = info.metadata[key][prop]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can now use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good catch! Will do. |
||
} else { | ||
// for keywords, add the localized keywords to the root language keywords | ||
var keywords = info.metadata[prop].concat(info.metadata[key][prop]); | ||
info.metadata[prop] = _.uniq(keywords); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safe to remove these? I still see them being referenced on the lines below:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nm, I didn't see that this was in the same function scope. Sigh, GitHub diffs... |
||
}); | ||
} | ||
|
||
if (info.metadata.description !== undefined) { | ||
info.metadata.shortdescription = StringUtils.truncate(info.metadata.description, 200); | ||
} | ||
|
@@ -224,9 +243,6 @@ define(function (require, exports, module) { | |
context.allowInstall = context.isCompatible && !context.isInstalled; | ||
|
||
if (Array.isArray(info.metadata.i18n) && info.metadata.i18n.length > 0) { | ||
var lang = brackets.getLocale(), | ||
shortLang = lang.split("-")[0]; | ||
|
||
context.translated = true; | ||
context.translatedLangs = | ||
info.metadata.i18n.map(function (value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ Move this plugin to the extensions\user\ folder to run the plugin. It will add a | |
|
||
* main.js – loads the Strings module for the plugin and uses mustache to localize html content | ||
|
||
* package.json - add the translation languages as in the example: `"i18n: ["en", "fr" ]` | ||
* package.json - add the translation languages as in the example: `"i18n: ["en", "fr" ]`. Also, add any localized metadata for displayed metadata in the Extension Manager, as in the example: `"fr": { "title": "localized title" }`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my proposed changes in #9028, this text is basically going away. It's most important to update the official package.json format docs, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Once this is merged, I can definitely update the official docs. |
||
|
||
* strings.js – uses i18n to load a strings.js file in the nls folder | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,9 @@ | |
"i18n": [ | ||
"en", | ||
"fr" | ||
] | ||
], | ||
"fr": { | ||
"title": "fr title to replace the root title", | ||
"description": "fr description to replace the root description" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: in the rest of this example, we used actual French translation. Google Translate should suffice... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Will do. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: no longer required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops. Nice catch.