Python SDK to support client applications #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. Initialization logic for TxNative and CDSHandler
See my blog post for the reasoning behind this.
2. Language management:
TxNative has the following properties:
source_language_code
(recommended, is set with thesource_language
kwarg to
setup
)current_language_code
(can beNone
, is set with thecurrent_language
kwarg to
setup
, or withset_current_language
)hardcoded_language_codes
(can beNone
, is )remote_languages
(is populated automatically)fetch_languages
will fetch the list of available languages from Transifexand save them in the
remote_languages
attribute. It will then return theintersection of the languages in
remote_languages
andhardcoded_language_codes
if the latter has been set or all the remotelanguages otherwise. Fetching from the CDS only happens the first time.
fetch_translations
accepts an optionallanguage_code
argument. If set,it will only fetch the specified language. This will also fetch the remote
languages lazily to check that the specified language is available.
set_current_language
will lazily fetch the remote languages. It will thenlazily fetch the translations for the specified language and finally set the
current_language_code
attribute to the specified language.The
language_code
argument totranslate
is now optional. If not set, thecurrent_language_code
attribute will be used.3. Event emitter
Same signatures as with the javascript SDK. You can call
tx.on(EVENT_LABEL, callback)
and then interesting things will happen when the current language is changed or when the translations are fetched4.
urwid
SDKSimple SDK to allow urwid applications to behave somewhat like react applications. See here for a demo