Code author: Sang Han <jjangsangy@gmail.com>
translate.
translator
(source, target, phrase, version='0.0 test', charset='utf-8')[source]¶Returns the url encoded string that will be pushed to the translation server for parsing.
List of acceptable language codes for source and target languages can be found as a JSON file in the etc directory.
Some source languages are limited in scope of the possible target languages that are available.
>>> from translate import translator
>>> translator('en', 'zh-TW', 'Hello World!')
'你好世界!'
Parameters: |
|
---|---|
Returns: | Request Interface |
Return type: | Dictionary |
translate.
coroutine
(func)[source]¶Initializes coroutine essentially priming it to the yield statement. Used as a decorator over functions that generate coroutines.
# Basic coroutine producer/consumer pattern
from translate import coroutine
@coroutine
def coroutine_foo(bar):
try:
while True:
baz = (yield)
bar.send(baz)
except GeneratorExit:
bar.close()
Parameters: | func (Function) – Unprimed Generator |
---|---|
Returns: | Initialized Coroutine |
Return type: | Function |
translate.
push_url
(interface)[source]¶Decorates a function returning the url of translation API. Creates and maintains HTTP connection state
Returns a dict response object from the server containing the translated text and metadata of the request body
Parameters: | interface (Function) – Callable Request Interface |
---|
translate.
source
(target, inputstream=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>)[source]¶Coroutine starting point. Produces text stream and forwards to consumers
Parameters: |
|
---|
translate.
spool
(iterable, maxlen=1250)[source]¶Consumes text streams and spools them together for more io efficient processes.
Parameters: |
|
---|
translate.
set_task
(translator, translit=False)[source]¶Task Setter Coroutine
End point destination coroutine of a purely consumer type. Delegates Text IO to the write_stream function.
Parameters: |
|
---|
translate.
write_stream
(script, output='trans')[source]¶Parameters: |
|
---|
translate.
accumulator
(init, update)[source]¶Generic accumulator function.
# Simplest Form
>>> a = 'this' + ' '
>>> b = 'that'
>>> c = functools.reduce(accumulator, a, b)
>>> c
'this that'
# The type of the initial value determines output type.
>>> a = 5
>>> b = Hello
>>> c = functools.reduce(accumulator, a, b)
>>> c
10
Parameters: |
|
---|---|
Returns: | Combined Values |
translate.
set_task
(translator, translit=False)[source]Task Setter Coroutine
End point destination coroutine of a purely consumer type. Delegates Text IO to the write_stream function.
Parameters: |
|
---|
translate.
write_stream
(script, output='trans')[source]Parameters: |
|
---|
translate.
translation_table
(language, filepath='supported_translations.json')[source]¶Opens up file located under the etc directory containing language codes and prints them out.
Parameters: | file (str) – Path to location of json file |
---|---|
Returns: | language codes |
Return type: | dict |