Index: cms/converters.py |
diff --git a/cms/converters.py b/cms/converters.py |
index afa4ee4f31ef51cf1d39ffa7453154a5b51a2f9e..3630ebf80d52cd983e8b947a24446abc8f15ffd1 100644 |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -133,12 +133,25 @@ class Converter: |
def re_escape(s): |
return re.escape(escape(s)) |
+ locale = self._params["locale"] |
+ duplicate_string = not default |
Sebastian Noack
2015/08/23 14:24:12
Nit: I find this variable name kind misleading. Th
kzar
2015/08/23 15:28:53
Done.
|
+ is_default_locale = locale == self._params["defaultlocale"] |
+ |
+ # Handle duplicated strings |
+ if duplicate_string: |
+ try: |
+ default = self._params["localedata"][name] |
+ except KeyError: |
+ raise Exception("Text not yet defined for string %s on page %s" % |
+ (name, self._params["page"])) |
+ elif is_default_locale: |
+ self._params["localedata"][name] = default |
+ |
# Extract tag attributes from default string |
default, saved_attributes, fixed_strings = self._attribute_parser.parse(default, self._params["page"]) |
# Get translation |
- locale = self._params["locale"] |
- if locale == self._params["defaultlocale"]: |
+ if is_default_locale: |
result = default |
elif name in localedata: |
result = localedata[name].strip() |
@@ -147,11 +160,12 @@ class Converter: |
self.missing_translations += 1 |
self.total_translations += 1 |
- # Perform callback with the string if required, e.g. for the translations script |
- callback = self._params["localized_string_callback"] |
- if callback: |
- callback(page, locale, name, result, comment, fixed_strings) |
- |
+ if not duplicate_string: |
+ # Perform callback with the string if required, |
+ # e.g. for the translations script |
+ callback = self._params["localized_string_callback"] |
+ if callback: |
+ callback(page, locale, name, result, comment, fixed_strings) |
# Insert fixed strings |
for i, fixed_string in enumerate(fixed_strings, 1): |
@@ -189,19 +203,20 @@ class Converter: |
def insert_localized_strings(self, text, escapes, to_html=lambda s: s): |
def lookup_string(match): |
name, comment, default = match.groups() |
- default = to_html(default).strip() |
- |
+ if default: |
Sebastian Noack
2015/08/23 14:24:12
Nit: If I understand the code correctly default is
kzar
2015/08/23 15:28:53
I found that default is actually sometimes None du
|
+ default = to_html(default).strip() |
return self.localize_string(self._params["page"], name, default, |
comment, self._params["localedata"], escapes) |
return re.sub( |
r"{{\s*" |
r"([\w\-]+)" # String ID |
- r"(?:\[(.*?)\])?" # Optional comment |
- r"\s+" |
- r"((?:(?!{{).|" # Translatable text |
- r"{{(?:(?!}}).)*}}" # Nested translation |
- r")*?)" |
+ r"(?:(?:\[(.*?)\])?" # Optional comment |
+ r"\s+" |
+ r"((?:(?!{{).|" # Translatable text |
+ r"{{(?:(?!}}).)*}}" # Nested translation |
+ r")*?)" |
+ r")?" |
r"}}", |
lookup_string, |
text, |