Пример #1
0
 def do_text(text, translit=False):
     text = unescape(text)
     if markdown_mode:
         text = markdown(text)
     if translit:
         return (translate(text, trans_from, args.trans_to), translate(text, trans_from, "devanagari"))
     elif qtags.intersection([".html", ".md"]):
         return str(process_html(text, args.media))
     else:
         return html_escape(text)
Пример #2
0
 def do_text(text, translit=False):
     text = unescape(text)
     if markdown_mode:
         text = str(post_markdown(markdown(text)))
     if translit:
         return (translate(text, trans_from, args.trans_to),
                 translate(text, trans_from, 'devanagari'))
     elif qtags.intersection(['.html', '.md']):
         return text
     else:
         return html_escape(text)
Пример #3
0
 def do_text(text, translit=False):
     text = unescape(text)
     if markdown_mode:
         text = markdown(text)
     if translit:
         return (translate(text, trans_from, args.trans_to),
                 translate(text, trans_from, 'devanagari'))
     elif qtags.intersection(['.html', '.md']):
         return str(process_html(text))
     else:
         return html_escape(text)
Пример #4
0
def translate(root,filename,lang):
    print 'Translating', filename
    dest_root = root.replace('/ru/','/'+lang+'/')
    if not os.path.exists(dest_root):
        os.makedirs(dest_root)

    input =  os.path.join(root,filename)
    output = os.path.join(dest_root,filename)

    if not os.path.isfile(output):
        trans.translate(lang,input,output)
Пример #5
0
 def do_text(text, translit=False):
     text = unescape(text)
     if markdown_mode:
         text = str(markdown(text))
     if translit:
         return (translate(text, trans_from, args.trans_to),
                 translate(text, trans_from, 'devanagari'))
     elif tags.intersection(['.html', '.md']):
         print tags, "html or md" ##
         return text
     else:
         return html_escape(text)
Пример #6
0
 def do_text(text, translit=False):
     print text, tags ##
     text = unescape(text)
     if markdown_mode:
         text = str(markdown(text))
     if translit:
         return (translate(text, trans_from, args.trans_to),
                 translate(text, trans_from, 'devanagari'))
     elif tags.intersection(['.html', '.md']):
         print qtags, "html or md" ##
         return text
     else:
         return html_escape(text)
Пример #7
0
    def parse_item(self, response, url):
        """
        parse the response of a `python requests.get()`

        @param response - an object of `requests.get()`
        @param url - current url object that has been crawled
        @return item
        """
        soup = bs4.BeautifulSoup(response.text, 'html.parser')

        # print("title: %s" % soup.title)

        it = Item()
        for link in soup.find_all('meta'):
            if link.get('name') == 'description':
                it.name_jp = link.get('content')
                it.name_zh = trans.translate(it.name_jp)
                it.link = response.url

        # print("item name_zh: %s" % it.name_zh)
        self.feed_new_urls(soup, url)
        return it
Пример #8
0
from trans import translate

to_translate = 'Hello how are you?'
print(translate(to_translate, 'hi'))
print(translate(to_translate, 'ar'))
print(translate(to_translate, 'ru'))
Пример #9
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/plain'
     python_string = self.request.get('python_string')
     self.response.write(trans.translate(python_string))
Пример #10
0
 def do_trans(text):
     return [translate(text, trans_from, args.trans_to),
             translate(text, trans_from, 'devanagari')]