[Bf-translations-svn] SVN commit: /data/svn/bf-translations [412] trunk/po/tools: Added small check over msgids to detect those without capital first letter ...

bf-translations at blender.org bf-translations at blender.org
Mon Feb 27 19:58:01 CET 2012


Revision: 412
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=412
Author:   mont29
Date:     2012-02-27 18:58:01 +0000 (Mon, 27 Feb 2012)
Log Message:
-----------
Added small check over msgids to detect those without capital first letter...

Modified Paths:
--------------
    trunk/po/tools/settings_template.py
    trunk/po/tools/update_pot.py
    trunk/po/tools/utils.py

Modified: trunk/po/tools/settings_template.py
===================================================================
--- trunk/po/tools/settings_template.py	2012-02-27 18:56:00 UTC (rev 411)
+++ trunk/po/tools/settings_template.py	2012-02-27 18:58:01 UTC (rev 412)
@@ -47,7 +47,73 @@
 # The gettext keywords.
 GETTEXT_KEYWORDS = ("IFACE_", "TIP_", "N_")
 
+# Should po parser warn when finding a first letter not capitalized?
+WARN_MSGID_NOT_CAPITALIZED = True
 
+# Strings that should not raise above warning!
+WARN_MSGID_NOT_CAPITALIZED_ALLOWED = {
+    "",  # Simplifies things... :p
+    "sin(x) / x",
+    "fBM",
+    "sqrt(x*x+y*y+z*z)",
+    "iTaSC",
+    "bItasc",
+    "px",
+    "mm",
+    "fStop",
+    "sRGB",
+    "iso-8859-15",
+    "utf-8",
+    "ascii",
+    "re",
+    "y",
+    "ac3",
+    "flac",
+    "mkv",
+    "mp2",
+    "mp3",
+    "ogg",
+    "wav",
+    "iTaSC parameters",
+    "vBVH",
+    "rv",
+    "en_US",
+    "fr_FR",
+    "it_IT",
+    "ru_RU",
+    "zh_CN",
+    "es",
+    "zh_TW",
+    "ar_EG",
+    "pt_BR",
+    "bg_BG",
+    "ca_AD",
+    "hr_HR",
+    "cs_CZ",
+    "nl_NL",
+    "fi_FI",
+    "de_DE",
+    "el_GR",
+    "id_ID",
+    "ja_JP",
+    "ki",
+    "ko_KR",
+    "ne_NP",
+    "fa_IR",
+    "pl_PL",
+    "ro_RO",
+    "sr_RS",
+    "sr_RS at latin",
+    "sv_SE",
+    "uk_UA",
+    "available with",                # Is part of multi-line msg.
+    "virtual parents",               # Is part of multi-line msg.
+    "description",                   # Addons' field. :/
+    "location",                      # Addons' field. :/
+    "author",                        # Addons' field. :/
+    "in memory to enable editing!"}  # Is part of multi-line msg.
+
+
 ###############################################################################
 # PATHS
 ###############################################################################

Modified: trunk/po/tools/update_pot.py
===================================================================
--- trunk/po/tools/update_pot.py	2012-02-27 18:56:00 UTC (rev 411)
+++ trunk/po/tools/update_pot.py	2012-02-27 18:58:01 UTC (rev 412)
@@ -43,7 +43,10 @@
 GETTEXT_XGETTEXT_EXECUTABLE = settings.GETTEXT_XGETTEXT_EXECUTABLE
 GETTEXT_KEYWORDS = settings.GETTEXT_KEYWORDS
 
+WARN_NC = settings.WARN_MSGID_NOT_CAPITALIZED
+NC_ALLOWED = settings.WARN_MSGID_NOT_CAPITALIZED_ALLOWED
 
+
 def generate_valid_potfiles(final_potfiles):
     "Generates a temp potfiles.in with aboslute paths."
     with open(FILE_NAME_POTFILES, 'r', 'utf-8') as f, \
@@ -126,6 +129,11 @@
                     context = line[len(CONTEXT_PREFIX):].split()[0]
                     line = line[len(CONTEXT_PREFIX)+len(context)+1:]
                 key = (line, context)
+                if (WARN_NC and line not in NC_ALLOWED and
+                    line[0].isalpha() and not line[0].isupper()):
+                    print("WARNING: msgid is not capitalized (\"{}\")!"
+                          "\n        {}"
+                          "".format(line, "\n        ".join(msgsrc_ls)))
                 if key not in pot_messages:
                     pot_messages[key] = {"msgid_lines": [line],
                                          "msgstr_lines": [""],

Modified: trunk/po/tools/utils.py
===================================================================
--- trunk/po/tools/utils.py	2012-02-27 18:56:00 UTC (rev 411)
+++ trunk/po/tools/utils.py	2012-02-27 18:58:01 UTC (rev 412)
@@ -27,6 +27,8 @@
 
 
 COMMENT_PREFIX = settings.COMMENT_PREFIX
+WARN_NC = settings.WARN_MSGID_NOT_CAPITALIZED
+NC_ALLOWED = settings.WARN_MSGID_NOT_CAPITALIZED_ALLOWED
 
 
 def stripeol(s):
@@ -40,13 +42,16 @@
 def parse_messages(fname):
     """
     Returns a tupple (messages, states, stats).
-    messages is an odereddict of dicts {ctxt: {msgid: {msgid_lines:, msgstr_lines:, comment_lines:}}}.
-    states is a dict of three sets of msgid, and a boolean flag indicating the .po is somewhat
-           broken {trans_msg:, fuzzy_msg:, comm_msg:, is_broken:}.
-    stats is a dict of values {tot_msg:, trans_msg:, tot_ttips:, trans_ttips:, comm_msg:,
-                               nbr_signs:, nbr_trans_signs:}.
-    Note: This function will silently "arrange" mis-formated entries, thus using afterward
-          write_messages() should always produce a po-valid file, though not correct!
+    messages is an odereddict of dicts
+        {ctxt: {msgid: {msgid_lines:, msgstr_lines:, comment_lines:}}}.
+    states is a dict of three sets of msgid, and a boolean flag indicating the
+        .po is somewhat broken {trans_msg:, fuzzy_msg:, comm_msg:, is_broken:}.
+    stats is a dict of values
+        {tot_msg:, trans_msg:, tot_ttips:, trans_ttips:, comm_msg:,
+         nbr_signs:, nbr_trans_signs:}.
+    Note: This function will silently "arrange" mis-formated entries, thus
+        using afterward write_messages() should always produce a po-valid file,
+        though not correct!
     """
     tot_messages = 0
     tot_tooltips = 0
@@ -79,10 +84,11 @@
 
 
     def clean_vars():
-        nonlocal reading_msgid, reading_msgstr, reading_msgctxt, reading_comment, \
-                 is_fuzzy, is_translated, is_commented, \
+        nonlocal reading_msgid, reading_msgstr, reading_msgctxt, \
+                 reading_comment, is_fuzzy, is_translated, is_commented, \
                  msgid_lines, msgstr_lines, msgctxt_lines, comment_lines
-        reading_msgid = reading_msgstr = reading_msgctxt = reading_comment = False
+        reading_msgid = reading_msgstr = reading_msgctxt = \
+                        reading_comment = False
         is_tooltip = is_fuzzy = is_translated = is_commented = False
         msgid_lines = []
         msgstr_lines = []
@@ -91,8 +97,8 @@
 
 
     def finalize_message():
-        nonlocal reading_msgid, reading_msgstr, reading_msgctxt, reading_comment, \
-                 is_fuzzy, is_translated, is_commented, \
+        nonlocal reading_msgid, reading_msgstr, reading_msgctxt, \
+                 reading_comment, is_fuzzy, is_translated, is_commented, \
                  msgid_lines, msgstr_lines, msgctxt_lines, comment_lines, \
                  messages, translated_messages, fuzzy_messages, \
                  commented_messages, \
@@ -104,6 +110,12 @@
         msgkey = (msgid, msgctxt)
         is_ttip = is_tooltip(msgid)
 
+        if (WARN_NC and msgid not in NC_ALLOWED and
+            msgid[0].isalpha() and not msgid[0].isupper()):
+            print("WARNING: msgid around line {} is not capitalized "
+                  "(\"{}\")!\n        {}".format(line_nr, msgid,
+                                          "\n        ".join(comment_lines)))
+
         # Never allow overriding existing msgid/msgctxt pairs!
         if msgkey in messages:
             clean_vars()
@@ -139,7 +151,7 @@
 
 
     with open(fname, 'r', "utf-8") as f:
-        for line in f:
+        for line_nr, line in enumerate(f):
             line = stripeol(line)
             if line == "":
                 finalize_message()
@@ -251,12 +263,15 @@
             if msgkey in commented:
                 if msgctxt:
                     f.write("\n{}msgctxt \"".format(COMMENT_PREFIX))
-                    f.write("\"\n{}\"".format(COMMENT_PREFIX).join(val["msgctxt_lines"]))
+                    f.write("\"\n{}\"".format(COMMENT_PREFIX).join(
+                                       val["msgctxt_lines"]))
                     f.write("\"")
                 f.write("\n{}msgid \"".format(COMMENT_PREFIX))
-                f.write("\"\n{}\"".format(COMMENT_PREFIX).join(val["msgid_lines"]))
+                f.write("\"\n{}\"".format(COMMENT_PREFIX).join(
+                                   val["msgid_lines"]))
                 f.write("\"\n{}msgstr \"".format(COMMENT_PREFIX))
-                f.write("\"\n{}\"".format(COMMENT_PREFIX).join(val["msgstr_lines"]))
+                f.write("\"\n{}\"".format(COMMENT_PREFIX).join(
+                                   val["msgstr_lines"]))
                 f.write("\"\n\n")
             else:
                 if msgctxt:
@@ -309,12 +324,18 @@
         glob_stats["contexts"] |= contexts
 
     lines = ("",
-             "{:>6.1%} done! ({} translated messages over {}).\n".format(lvl, trans_msgs, tot_msgs),
-             "{:>6.1%} of messages are tooltips ({} over {}).\n".format(lvl_ttips, tot_ttips, tot_msgs),
-             "{:>6.1%} of tooltips are translated ({} over {}).\n".format(lvl_trans_ttips, trans_ttips, tot_ttips),
-             "{:>6.1%} of translated messages are tooltips ({} over {}).\n".format(lvl_ttips_in_trans, trans_ttips, trans_msgs),
-             "{:>6.1%} of messages are commented ({} over {}).\n".format(lvl_comm, comm_msgs, comm_msgs+tot_msgs),
-             "This translation is currently made of {} signs.\n".format(nbr_trans_signs))
+             "{:>6.1%} done! ({} translated messages over {}).\n"
+             "".format(lvl, trans_msgs, tot_msgs),
+             "{:>6.1%} of messages are tooltips ({} over {}).\n"
+             "".format(lvl_ttips, tot_ttips, tot_msgs),
+             "{:>6.1%} of tooltips are translated ({} over {}).\n"
+             "".format(lvl_trans_ttips, trans_ttips, tot_ttips),
+             "{:>6.1%} of translated messages are tooltips ({} over {}).\n"
+             "".format(lvl_ttips_in_trans, trans_ttips, trans_msgs),
+             "{:>6.1%} of messages are commented ({} over {}).\n"
+             "".format(lvl_comm, comm_msgs, comm_msgs+tot_msgs),
+             "This translation is currently made of {} signs.\n"
+             "".format(nbr_trans_signs))
     print(prefix.join(lines))
     return 0
 



More information about the Bf-translations-svn mailing list