Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: cms/sources.py

Issue 5694103719247872: Issue 2133 - Allow to specify default translation inline in pages rather than in a separate file (Closed)
Patch Set: Addressed comments Created March 12, 2015, 8:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cms/converters.py ('k') | cms/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 24 matching lines...) Expand all
35 default_locale = config.get("general", "defaultlocale") 35 default_locale = config.get("general", "defaultlocale")
36 default_page = config.get("general", "defaultpage") 36 default_page = config.get("general", "defaultpage")
37 37
38 checked_page = page 38 checked_page = page
39 if config.has_option("locale_overrides", page): 39 if config.has_option("locale_overrides", page):
40 checked_page = config.get("locale_overrides", page) 40 checked_page = config.get("locale_overrides", page)
41 41
42 if self.has_localizable_file(default_locale, checked_page): 42 if self.has_localizable_file(default_locale, checked_page):
43 if not self.has_localizable_file(locale, checked_page): 43 if not self.has_localizable_file(locale, checked_page):
44 locale = default_locale 44 locale = default_locale
45 elif self.has_locale(default_locale, checked_page): 45 elif self.has_page(checked_page):
46 if not self.has_locale(locale, checked_page): 46 if not self.has_locale(locale, checked_page):
47 locale = default_locale 47 locale = default_locale
48 else: 48 else:
49 print >>sys.stderr, "Warning: Link to %s cannot be resolved" % page 49 print >>sys.stderr, "Warning: Link to %s cannot be resolved" % page
50 50
51 if page == default_page: 51 if page == default_page:
52 page = "" 52 page = ""
53 53
54 path = "/%s/%s" % (locale, page) 54 path = "/%s/%s" % (locale, page)
55 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:]) 55 return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:])
(...skipping 11 matching lines...) Expand all
67 @staticmethod 67 @staticmethod
68 def page_filename(page, format): 68 def page_filename(page, format):
69 return "pages/%s.%s" % (page, format) 69 return "pages/%s.%s" % (page, format)
70 70
71 def list_pages(self): 71 def list_pages(self):
72 for filename in self.list_files("pages"): 72 for filename in self.list_files("pages"):
73 root, ext = os.path.splitext(filename) 73 root, ext = os.path.splitext(filename)
74 format = ext[1:].lower() 74 format = ext[1:].lower()
75 yield root, format 75 yield root, format
76 76
77 def has_page(self, page, format): 77 def has_page(self, page, format=None):
78 return self.has_file(self.page_filename(page, format)) 78 if format is None:
79 from .converters import converters
80 return any(
81 self.has_page(page, format)
82 for format in converters.iterkeys()
83 )
84 else:
85 return self.has_file(self.page_filename(page, format))
79 86
80 def read_page(self, page, format): 87 def read_page(self, page, format):
81 return self.read_file(self.page_filename(page, format)) 88 return self.read_file(self.page_filename(page, format))
82 89
83 # 90 #
84 # Localizable files helpers 91 # Localizable files helpers
85 # 92 #
86 93
87 @staticmethod 94 @staticmethod
88 def localizable_file_filename(locale, filename): 95 def localizable_file_filename(locale, filename):
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return 259 return
253 260
254 for filename in files: 261 for filename in files:
255 path = os.path.join(dir, filename) 262 path = os.path.join(dir, filename)
256 if os.path.isfile(path): 263 if os.path.isfile(path):
257 result.append(relpath + filename) 264 result.append(relpath + filename)
258 elif os.path.isdir(path): 265 elif os.path.isdir(path):
259 do_list(path, relpath + filename + "/") 266 do_list(path, relpath + filename + "/")
260 do_list(self.get_path(subdir), "") 267 do_list(self.get_path(subdir), "")
261 return result 268 return result
OLDNEW
« no previous file with comments | « cms/converters.py ('k') | cms/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld