Index: chrome/common/extensions/docs/server2/samples_data_source.py |
diff --git a/chrome/common/extensions/docs/server2/samples_data_source.py b/chrome/common/extensions/docs/server2/samples_data_source.py |
index c8e7fc4d0387711ede2e859a6181e8c34c64fce4..0e7f0c5f2ca2bd97b03fa622ec9c0bd1e92d4eff 100644 |
--- a/chrome/common/extensions/docs/server2/samples_data_source.py |
+++ b/chrome/common/extensions/docs/server2/samples_data_source.py |
@@ -12,6 +12,10 @@ class SamplesDataSource(object): |
self._fetcher = fetcher |
self._cache = cache_builder.build(self._MakeSamplesList) |
self._samples_path = samples_path |
+ self._headers = {} |
not at google - send to devlin
2012/07/20 01:28:21
let's just bind this to the request. Easier to und
cduvall
2012/07/20 19:40:50
Done.
|
+ |
+ def SetHeaders(self, headers): |
+ self._headers = headers |
def _GetApiItems(self, js_file): |
return set(re.findall('(chrome\.[a-zA-Z0-9\.]+)', js_file)) |
@@ -20,11 +24,36 @@ class SamplesDataSource(object): |
api, name = item.replace('chrome.', '').split('.', 1) |
return api + '.html#' + prefix + '-' + name |
+ def _FetchFile(self, filename): |
+ return self._fetcher.Read([filename]).Get()[filename] |
not at google - send to devlin
2012/07/20 01:28:21
Seen this pattern in a couple of places now.
Woul
cduvall
2012/07/20 19:40:50
Done.
|
+ |
def _GetDataFromManifest(self, path): |
- manifest_path = path + '/manifest.json' |
- manifest = self._fetcher.Read([manifest_path]).Get()[manifest_path] |
+ manifest = self._FetchFile(path + '/manifest.json') |
manifest_json = json.loads(manifest) |
- return (manifest_json.get('name'), manifest_json.get('description')) |
+ name = manifest_json.get('name', '') |
+ description = manifest_json.get('description', '') |
+ if name.startswith('__MSG_') or description.startswith('__MSG_'): |
not at google - send to devlin
2012/07/20 01:28:21
Won't this cache only the language in the header?
cduvall
2012/07/20 19:40:50
Done.
|
+ default_language = manifest_json['default_locale'] |
+ if 'Accept-Language' in self._headers: |
not at google - send to devlin
2012/07/20 01:28:21
for thsi kind of thing, would prefer to see someth
cduvall
2012/07/20 19:40:50
Done.
|
+ languages = filter(lambda x: x != 'q', |
+ re.findall('([a-zA-Z]+\-[a-zA-Z]+|[a-zA-Z]+)', |
+ self._headers['Accept-Language'])) |
+ languages = [l.replace('-', '_') for l in languages] |
not at google - send to devlin
2012/07/20 01:28:21
l as a short variable is like the most confusing s
cduvall
2012/07/20 19:40:50
Very true, sorry about that.
|
+ locales_path = path + '/_locales/' |
+ locales = [l.strip('/') for l in self._FetchFile(locales_path)] |
+ for language in languages: |
+ if language in locales: |
+ default_language = language |
+ break |
+ locale_json = json.loads(unicode( |
+ self._FetchFile(locales_path + default_language + '/messages.json'), |
+ 'latin-1')) |
+ if name.startswith('__MSG_'): |
+ name = locale_json[name[len('__MSG_'):-2]]['message'] |
+ if description.startswith('__MSG_'): |
+ description = locale_json[description[len('__MSG_'):-2]]['message'] |
+ |
+ return (name, description) |
def _MakeSamplesList(self, files): |
samples_list = [] |