Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

fix Issue #8953- "Localizing package metadata in Extension Manager" #8987

Merged
merged 14 commits into from
Sep 19, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/extensibility/ExtensionManagerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ define(function (require, exports, module) {
context.isCompatible = context.isCompatibleLatest = true;
}

var lang = brackets.getLocale(),
shortLang = lang.split("-")[0];

// Extension metadata might have localized content. If so, overlay those strings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: two spaces

Copy link
Contributor Author

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.

if (info.metadata.hasOwnProperty(shortLang)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for both lang and shortLang, so that you can, for example, also use the key "zh-cn".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Will do.

var prop;
for (prop in info.metadata[shortLang]) {
if (info.metadata[shortLang].hasOwnProperty(prop)) {
info.metadata[prop] = info.metadata[shortLang][prop];
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Will do.

}
}
}

if (info.metadata.description !== undefined) {
info.metadata.shortdescription = StringUtils.truncate(info.metadata.description, 200);
}
Copy link
Member

Choose a reason for hiding this comment

The 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:

userLangIndex = locales.indexOf(lang);
userLangIndex = locales.indexOf(shortLang);

Copy link
Member

Choose a reason for hiding this comment

The 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...

Expand All @@ -224,9 +237,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) {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/samples/LocalizationExample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }`.
Copy link
Member

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.

Copy link
Contributor Author

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.


* strings.js – uses i18n to load a strings.js file in the nls folder

Expand Down
6 changes: 5 additions & 1 deletion src/extensions/samples/LocalizationExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"i18n": [
"en",
"fr"
]
],
"fr": {
"title": "fr title to replace the root title",
"description": "fr description to replace the root description"
}
Copy link
Member

Choose a reason for hiding this comment

The 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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will do.

}