-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphrase_strings.py
95 lines (82 loc) · 4.15 KB
/
phrase_strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# https://github.com/phrase/phrase-python
# Expects an environment variable named PHRASE_DISCOVERY_ACCESS_TOKEN to be set.
from __future__ import print_function
import os
import json
import phrase_api
from phrase_api.rest import ApiException
project_id = '88ffd4d5abd6494131fabb1a271950b8' # mkDocs
def load_configuration():
configuration = phrase_api.Configuration()
configuration.api_key_prefix['Authorization'] = 'token'
configuration.host = "https://api.us.app.phrase.com/v2/"
access_token = 'PHRASE_DISCOVERY_ACCESS_TOKEN'
if access_token in os.environ:
configuration.api_key['Authorization'] = os.environ[access_token]
else:
print(f'{access_token} does not exist')
exit(1)
return configuration
def load_locale(locale):
configuration = load_configuration()
# Enter a context with an instance of the API client
with phrase_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = phrase_api.LocalesApi(api_client)
id = locale
x_phrase_app_otp = ''
if_modified_since = ''
if_none_match = ''
branch = ''
file_format = 'json'
tags = ''
tag = ''
include_empty_translations = True
exclude_empty_zero_forms = True
include_translated_keys = True
keep_notranslate_tags = True
convert_emoji = True
format_options = None
encoding = ''
skip_unverified_translations = False
include_unverified_translations = True
use_last_reviewed_version = False
fallback_locale_id = ''
source_locale_id = 'en'
try:
# Download a locale
api_response = api_instance.locale_download(project_id, id,
x_phrase_app_otp=x_phrase_app_otp,
if_modified_since=if_modified_since,
if_none_match=if_none_match,
branch=branch, file_format=file_format,
tags=tags, tag=tag,
include_empty_translations=include_empty_translations,
exclude_empty_zero_forms=exclude_empty_zero_forms,
include_translated_keys=include_translated_keys,
keep_notranslate_tags=keep_notranslate_tags,
convert_emoji=convert_emoji,
format_options=format_options,
encoding=encoding,
skip_unverified_translations=skip_unverified_translations,
include_unverified_translations=include_unverified_translations,
use_last_reviewed_version=use_last_reviewed_version,
fallback_locale_id=fallback_locale_id,
source_locale_id=source_locale_id)
f = open(api_response, 'r')
data = json.load(f)
return data
except ApiException as e:
print("Exception when calling LocalesApi->locale_download: %s\n" % e)
def list_locales():
configuration = load_configuration()
# Enter a context with an instance of the API client
with phrase_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = phrase_api.LocalesApi(api_client)
# branch = 'my-feature-branch' # str | specify the branch to use
try:
api_response = api_instance.locales_list(str(project_id), page=1, per_page=99)
except ApiException as e:
print("Exception when calling LocalesApi->locales_list: %s\n" % e)
return api_response