-
Notifications
You must be signed in to change notification settings - Fork 7.6k
fix Issue #8953- "Localizing package metadata in Extension Manager" #8987
Conversation
var lang = brackets.getLocale(), | ||
shortLang = lang.split("-")[0]; | ||
|
||
// Extension metadata might have localized content. If so, overlay those strings. |
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: two spaces
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.
@marcelgerber Do you mean the spaces separating the two sentences? Ok.
Hm, I wonder if we should have something like navigator.languages in Brackets (maybe in LocalizationUtils). It would make such use cases a lot easier.
|
var prop; | ||
for (prop in info.metadata[shortLang]) { | ||
if (info.metadata[shortLang].hasOwnProperty(prop)) { | ||
info.metadata[prop] = info.metadata[shortLang][prop]; |
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.
For keywords, it's probably best to leave the original in so you can search in both languages.
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.
Good idea. Will do.
@marcelgerber navigator.languages looks like a good idea, but probably more of a bigger user story to tackle. Pushed code changes per review. Ready for review. |
var key = useShortLang ? shortLang : lang, | ||
prop; | ||
for (prop in info.metadata[key]) { | ||
if (info.metadata[key].hasOwnProperty(prop)) { |
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.
The coding conventions recommend using _.forEach()
or _.some()
instead of for-in
.
https://github.com/adobe/brackets/wiki/Brackets-Coding-Conventions#apis-to-use-or-avoid
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.
Good catch!
Great suggestion, @marcelgerber. |
_.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 comment
The reason will be displayed to describe this comment to others. Learn more.
You can now use value
instead of info.metadata[key][prop]
. Same below.
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.
Ah, good catch! Will do.
LGTM. Works great in practice. |
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 comment
The 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 comment
The 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.
@peterflynn You mentioned earlier today that you had some concerns about the structure of the properties in the |
Hm, it would be best to let the user search for both the original and the translated title & description, but that's probably out of scope. |
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Once this is merged, I can definitely update the official docs.
Some higher-level feedback... 1) We probably shouldn't allow fields like I think we should have a whitelist of which properties can be overridden. Maybe just 2) Why special-case To keep it simple, I'd suggest we not try to do any special merging or concatenating at this point, for any properties. 3) Having all the locales sit as top-level keys in package.json risks having collisions, or at least is less structured than it could be. How about we put everything underneath a single top-level key, something like this:
|
@peterflynn Great observations. I can definitely do the first two. For the third, is there a reason why you propose the additional |
Whoops -- ignore that last question re: the third. I see what you're referring to in your earlier inline comment. |
@@ -28,7 +28,8 @@ | |||
define(function (require, exports, module) { | |||
"use strict"; | |||
|
|||
var Strings = require("strings"), | |||
var _ = require("thirdparty/lodash"), |
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.
var lang = brackets.getLocale(), | ||
shortLang = lang.split("-")[0]; | ||
[shortLang, lang].forEach(function (locale) { | ||
if (info.metadata["package-i18n"] !== undefined && |
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: this should just be if (info.metadata["package-i18n"]
(without undefined check). Could also move that clause outside the forEach() if you want...
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.
Good suggestions. Will do.
@bchintx Looks good -- just two small nits. |
I'd like to leave the property called Pushing the rest of the requested code review changes. |
Added unit tests to confirm that the translated metadata actually appears in the Extension Manager view. @peterflynn Ready for final review. |
runs(function () { | ||
spyOn(view.model, "dispose").andCallThrough(); | ||
}); | ||
} |
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.
This duplicates the code in describe("ExtensionManagerView")
-- could you just hoist up that existing function so it can be called by both test suites?
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.
Good call. I was trying out the Code Folding extension for the first time, and didn't notice that I had forgotten about copy-pasting from above.
@bchintx Sorry, one last request to reduce code duplication in the unit tests |
} | ||
}); | ||
|
||
describe("when showing registry entries-i18n", function () { |
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: we don't need another level of describe() here
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.
ok. Was just matching the code block above.
@peterflynn pushed requested changes. Thanks for the review. |
@bchintx I had in mind to avoid duplicating |
fix Issue #8953- "Localizing package metadata in Extension Manager"
Cool. Thanks, @peterflynn |
fix Issue #8953- "Localizing package metadata in Extension Manager"
This change adds Extension Manager support for localized extension package metadata. If the localized property is present (ie. property matching the short language name), then the additional provided properties will overlay any otherwise-defined properties. These localized strings will then be displayed in the Extension Manager dialog for those extensions that provide them.
note: The localized content is completely optional.
For example, in this code sample, the French
title
anddescription
properties would be overlayed with the given, localized strings.