Subversion Repositories LCARS

Rev

Rev 296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 296 Rev 297
Line 53... Line 53...
53
        return 1 if len(b) < len(a) else 0
53
        return 1 if len(b) < len(a) else 0
54
54
55
    return cmp_to_key(sort_dict_alnum_vulcan)
55
    return cmp_to_key(sort_dict_alnum_vulcan)
56
56
57
class VulcanDictionary (Dictionary):
57
class VulcanDictionary (Dictionary):
-
 
58
    """
-
 
59
   
-
 
60
    """
58
    def translate (self, phrase, search_prefix=True, search_plural=True):
61
    def translate (self, phrase, search_prefix=True, search_plural=True):
59
        dictionary = self
62
        """
60
63
       
-
 
64
        :param phrase:
-
 
65
        :type phrase:
-
 
66
        :param search_prefix:
-
 
67
        :type search_prefix:
-
 
68
        :param search_plural:
-
 
69
        :type search_plural:
-
 
70
        """
61
        translation = super().translate(phrase)
71
        translation = super().translate(phrase)
62
        if translation is not None:
72
        if translation is not None:
63
            return translation
73
            return translation
64
        else:
74
        else:
65
            expr_translation = dictionary.translate_expression(phrase)
75
            expr_translation = self.translate_expression(phrase)
66
            if expr_translation is not None:
76
            if expr_translation is not None:
67
                return expr_translation
77
                return expr_translation
68
78
69
            if search_prefix:
79
            if search_prefix:
70
                # find prefix
80
                # find prefix
Line 88... Line 98...
88
                        head_translation['en'] += ' (pl.)'
98
                        head_translation['en'] += ' (pl.)'
89
                        return head_translation
99
                        return head_translation
90
100
91
        return None
101
        return None
92
102
-
 
103
    def clean_entry(self, phrase):
-
 
104
        """
-
 
105
        Replace GV Media Script parens with FSE parens
-
 
106
        :param phrase:
-
 
107
        :type phrase:
-
 
108
        """
-
 
109
        return sub(
-
 
110
            r'(\([^)]*\))|\|([^|)]+)\|',
-
 
111
            lambda m: '({0})'.format(m.group(2)) if m.group(2) else m.group(1),
-
 
112
            phrase)
-
 
113
93
if __name__ == '__main__':
114
if __name__ == '__main__':
94
    if len(argv) < 2:
115
    if len(argv) < 2:
95
        print('Nothing to translate.', end='\n\n', file=stderr)
116
        print('Nothing to translate.', end='\n\n', file=stderr)
96
        cli_help()
117
        cli_help()
97
        exit(1)
118
        exit(1)
Line 155... Line 176...
155
                        word['en']
176
                        word['en']
156
                        if (hasattr(word, "get") and word.get('en', None) is not None)
177
                        if (hasattr(word, "get") and word.get('en', None) is not None)
157
                        else word,
178
                        else word,
158
                    words)),
179
                    words)),
159
                min_level=2)
180
                min_level=2)
160
            # dmsg(dictionary._expressions)
181
#             for key, value in dictionary._expressions.items():
-
 
182
#                 dmsg(key, value, min_level=3)