Mercurial > genshi > genshi-test
comparison genshi/filters/i18n.py @ 891:b40dbfee9ba6
Removed some obsolete/unused code from the i18n filter.
author | cmlenz |
---|---|
date | Wed, 21 Apr 2010 07:38:37 +0000 |
parents | 18dee397f8e1 |
children | 1de952fd479e |
comparison
equal
deleted
inserted
replaced
890:158aafe7187f | 891:b40dbfee9ba6 |
---|---|
147 return super(MsgDirective, cls).attach(template, stream, value.strip(), | 147 return super(MsgDirective, cls).attach(template, stream, value.strip(), |
148 namespaces, pos) | 148 namespaces, pos) |
149 | 149 |
150 def __call__(self, stream, directives, ctxt, **vars): | 150 def __call__(self, stream, directives, ctxt, **vars): |
151 gettext = ctxt.get('_i18n.gettext') | 151 gettext = ctxt.get('_i18n.gettext') |
152 dgettext = ctxt.get('_i18n.dgettext') | |
153 if ctxt.get('_i18n.domain'): | 152 if ctxt.get('_i18n.domain'): |
153 dgettext = ctxt.get('_i18n.dgettext') | |
154 assert hasattr(dgettext, '__call__'), \ | 154 assert hasattr(dgettext, '__call__'), \ |
155 'No domain gettext function passed' | 155 'No domain gettext function passed' |
156 gettext = lambda msg: dgettext(ctxt.get('_i18n.domain'), msg) | 156 gettext = lambda msg: dgettext(ctxt.get('_i18n.domain'), msg) |
157 | 157 |
158 def _generate(): | 158 def _generate(): |
736 | 736 |
737 GETTEXT_FUNCTIONS = ('_', 'gettext', 'ngettext', 'dgettext', 'dngettext', | 737 GETTEXT_FUNCTIONS = ('_', 'gettext', 'ngettext', 'dgettext', 'dngettext', |
738 'ugettext', 'ungettext') | 738 'ugettext', 'ungettext') |
739 | 739 |
740 def extract(self, stream, gettext_functions=GETTEXT_FUNCTIONS, | 740 def extract(self, stream, gettext_functions=GETTEXT_FUNCTIONS, |
741 search_text=True, msgbuf=None, comment_stack=None): | 741 search_text=True, comment_stack=None): |
742 """Extract localizable strings from the given template stream. | 742 """Extract localizable strings from the given template stream. |
743 | 743 |
744 For every string found, this function yields a ``(lineno, function, | 744 For every string found, this function yields a ``(lineno, function, |
745 message, comments)`` tuple, where: | 745 message, comments)`` tuple, where: |
746 | 746 |
788 search_text = False | 788 search_text = False |
789 if comment_stack is None: | 789 if comment_stack is None: |
790 comment_stack = [] | 790 comment_stack = [] |
791 skip = 0 | 791 skip = 0 |
792 | 792 |
793 # Un-comment bellow to extract messages without adding directives | |
794 xml_lang = XML_NAMESPACE['lang'] | 793 xml_lang = XML_NAMESPACE['lang'] |
795 | 794 |
796 for kind, data, pos in stream: | 795 for kind, data, pos in stream: |
797 if skip: | 796 if skip: |
798 if kind is START: | 797 if kind is START: |
819 for lineno, funcname, text, comments in self.extract( | 818 for lineno, funcname, text, comments in self.extract( |
820 _ensure(value), gettext_functions, | 819 _ensure(value), gettext_functions, |
821 search_text=False): | 820 search_text=False): |
822 yield lineno, funcname, text, comments | 821 yield lineno, funcname, text, comments |
823 | 822 |
824 if msgbuf: | |
825 msgbuf.append(kind, data, pos) | |
826 | |
827 elif not skip and search_text and kind is TEXT: | 823 elif not skip and search_text and kind is TEXT: |
828 if not msgbuf: | 824 text = data.strip() |
829 text = data.strip() | 825 if text and [ch for ch in text if ch.isalpha()]: |
830 if text and [ch for ch in text if ch.isalpha()]: | 826 yield pos[1], None, text, comment_stack[-1:] |
831 yield pos[1], None, text, comment_stack[-1:] | |
832 else: | |
833 msgbuf.append(kind, data, pos) | |
834 | |
835 elif not skip and msgbuf and kind is END: | |
836 msgbuf.append(kind, data, pos) | |
837 if not msgbuf.depth: | |
838 yield msgbuf.lineno, None, msgbuf.format(), [ | |
839 c for c in msgbuf.comment if c | |
840 ] | |
841 msgbuf = None | |
842 | 827 |
843 elif kind is EXPR or kind is EXEC: | 828 elif kind is EXPR or kind is EXEC: |
844 if msgbuf: | |
845 msgbuf.append(kind, data, pos) | |
846 for funcname, strings in extract_from_code(data, | 829 for funcname, strings in extract_from_code(data, |
847 gettext_functions): | 830 gettext_functions): |
848 # XXX: Do we need to grab i18n:comment from comment_stack ??? | 831 # XXX: Do we need to grab i18n:comment from comment_stack ??? |
849 yield pos[1], funcname, strings, [] | 832 yield pos[1], funcname, strings, [] |
850 | 833 |
862 # in case we're in the presence of something like: | 845 # in case we're in the presence of something like: |
863 # <p i18n:comment="foo">Foo</p> | 846 # <p i18n:comment="foo">Foo</p> |
864 messages = self.extract( | 847 messages = self.extract( |
865 substream, gettext_functions, | 848 substream, gettext_functions, |
866 search_text=search_text and not skip, | 849 search_text=search_text and not skip, |
867 msgbuf=msgbuf, comment_stack=comment_stack) | 850 comment_stack=comment_stack) |
868 for lineno, funcname, text, comments in messages: | 851 for lineno, funcname, text, comments in messages: |
869 yield lineno, funcname, text, comments | 852 yield lineno, funcname, text, comments |
870 directives.pop(idx) | 853 directives.pop(idx) |
871 elif not isinstance(directive, I18NDirective): | 854 elif not isinstance(directive, I18NDirective): |
872 # Remove all other non i18n directives from the process | 855 # Remove all other non i18n directives from the process |
876 # Extract content if there's no directives because | 859 # Extract content if there's no directives because |
877 # strip was pop'ed and not because comment was pop'ed. | 860 # strip was pop'ed and not because comment was pop'ed. |
878 # Extraction in this case has been taken care of. | 861 # Extraction in this case has been taken care of. |
879 messages = self.extract( | 862 messages = self.extract( |
880 substream, gettext_functions, | 863 substream, gettext_functions, |
881 search_text=search_text and not skip, msgbuf=msgbuf) | 864 search_text=search_text and not skip) |
882 for lineno, funcname, text, comments in messages: | 865 for lineno, funcname, text, comments in messages: |
883 yield lineno, funcname, text, comments | 866 yield lineno, funcname, text, comments |
884 | 867 |
885 for directive in directives: | 868 for directive in directives: |
886 if isinstance(directive, ExtractableI18NDirective): | 869 if isinstance(directive, ExtractableI18NDirective): |
888 for funcname, text, comments in messages: | 871 for funcname, text, comments in messages: |
889 yield pos[1], funcname, text, comments | 872 yield pos[1], funcname, text, comments |
890 else: | 873 else: |
891 messages = self.extract( | 874 messages = self.extract( |
892 substream, gettext_functions, | 875 substream, gettext_functions, |
893 search_text=search_text and not skip, msgbuf=msgbuf) | 876 search_text=search_text and not skip) |
894 for lineno, funcname, text, comments in messages: | 877 for lineno, funcname, text, comments in messages: |
895 yield lineno, funcname, text, comments | 878 yield lineno, funcname, text, comments |
896 | 879 |
897 if in_comment: | 880 if in_comment: |
898 comment_stack.pop() | 881 comment_stack.pop() |