Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24529 from KevinGrandon/bug_1074417_search_locali…
Browse files Browse the repository at this point in the history
…zed_apps

Bug 1074417 - [Search] Search translanted app names for query
  • Loading branch information
KevinGrandon committed Oct 1, 2014
2 parents a7599bb + 5f91eeb commit c409ecf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/search/js/providers/local_apps.js
Expand Up @@ -119,11 +119,26 @@
});
},

/**
* Checks if an app manifest matches a query.
*/
matches: function(manifest, query) {
query = query.toLowerCase();

// Get the localized name from the query.
var userLang = document.documentElement.lang;
var locales = manifest.locales;
var localized = locales && locales[userLang] && locales[userLang].name;
localized = localized || '';

return manifest.name.toLowerCase().indexOf(query) != -1 ||
localized.toLowerCase().indexOf(query) != -1;
},

find: function(query) {
var results = [];

this.appListing.forEach(function(manifest) {
if (manifest.name.toLowerCase().indexOf(query.toLowerCase()) != -1) {
if (this.matches(manifest, query)) {
results.push({
app: this.apps[manifest.manifestURL],
entryPoint: manifest.entryPoint
Expand Down
15 changes: 15 additions & 0 deletions apps/search/test/unit/providers/local_apps_test.js
Expand Up @@ -40,6 +40,16 @@ suite('search/providers/local_apps', function() {
launch_path: '/fakeapp3/index.html',
name: 'Mooilla Fake App 3'
}
},{
manifest: {
launch_path: '/fakeapp4/index.html',
name: 'Blah blah',
locales: {
foobar: {
name: 'localized app'
}
}
}
}];
_blValue = ['/fakeapp1-1/index.html'];

Expand Down Expand Up @@ -113,6 +123,11 @@ suite('search/providers/local_apps', function() {
assert.equal(results.length, 3);
});

test('Search for localized apps', function() {
document.documentElement.lang = 'foobar';
var results = subject.find('localized');
assert.equal(results.length, 1);
});
});

});

0 comments on commit c409ecf

Please sign in to comment.