Utils
hypha.apply.translate.utils
¶
get_available_translations
¶
Get languages available for translation
Parameters:
-
from_codes(Optional[List[str]], default:None) –optionally specify a list of languages to view available translations to
Returns:
-
List[Package]–A list of argostranslate package objects that are installed and available.
Source code in hypha/apply/translate/utils.py
get_translation_params
¶
Attempts to extract the fl (from language) & tl (to language) params from the provided URL or request object
Return values are not validated to ensure languages are valid & packages exist.
Parameters:
-
url(str, default:None) –the URL to extract the params from
Returns:
-
tuple(Tuple[str, str] | None) –in the format of (\<from language>, \<to language>)
Raises:
-
ValueError–If
url/requestare not provided OR if both are provided
Source code in hypha/apply/translate/utils.py
get_lang_name
¶
get_language_choices_json
¶
Generate a JSON output of available translation options
Utilized for populating the reactive form fields on the client side
Parameters:
-
request(HttpRequest) –an
HttpRequestcontaining an "Hx-Current-Url" header to extract current translation params from
Returns:
-
str–A JSON string in the format of:
-
str–```
-
str–[ { "value": "
", "label": " ", "to": [ { "value": " ", "label": " " "selected": } ], "selected": }, ... -
str–]
-
str–```
Source code in hypha/apply/translate/utils.py
translate_application_form_data
¶
Translate the content of an application's live revision form_data.
Will parse fields that contain both plaintext & HTML, extracting & replacing strings.
NOTE: Mixed formatting like <p>Hey from <strong>Hypha</strong></p> will result in a
string that is stripped of text formatting (untranslated: <p>Hey from Hypha</p>). On
the other hand, unmixed strings like <p><strong>Hey from Hypha</strong></p> will be
replaced within formatting tags.
Parameters:
-
application–the application to translate
-
from_code(str) –the ISO 639 code of the original language
-
to_code(str) –the ISO 639 code of the language to translate to
Returns:
-
dict–The
form_datawith values translated (including nested HTML strings)
Source code in hypha/apply/translate/utils.py
has_valid_str
¶
Checks that an Tag contains a valid text element and/or string.
Parameters:
-
tag(Tag) –a
bs4.element.Tag