Skip to content

Instantly share code, notes, and snippets.

@gmoraleda
Last active February 19, 2021 10:44
Show Gist options
  • Save gmoraleda/99e7157b78a400e29a6a0d17b178dc8a to your computer and use it in GitHub Desktop.
Save gmoraleda/99e7157b78a400e29a6a0d17b178dc8a to your computer and use it in GitHub Desktop.
POEditor Integration
import requests
def to_camel_case(snake_str):
components = snake_str.split("_")
return components[0] + "".join(x.title() for x in components[1:])
def getTerms():
data = (
("api_token", "your_api_token"),
("id", "your_project_id"),
)
urlResponse = requests.post("https://api.poeditor.com/v2/terms/list", data=data)
values = urlResponse.json()
terms = values["result"]["terms"]
file = open("LocalizationTest/Strings.swift", "w")
file.write(
"""
// Strings.swift
// Generated file. Do not modify.
import Foundation
enum Strings: String {
"""
)
for term in terms:
rawValue = term["term"]
formatted = to_camel_case(term["term"])
file.write("\tcase " + formatted + " = \"" + rawValue + "\"\n")
file.write("}")
file.close()
def getGermanTranslations():
data = (
("api_token", "your_api_token"),
("id", "your_project_id"),
("language", "de"),
("type", "apple_strings"),
)
urlResponse = requests.post("https://api.poeditor.com/v2/projects/export", data=data)
values = urlResponse.json()
download_url = values["result"]["url"]
fileResponse = requests.get(download_url)
open("LocalizationTest/de.lproj/Localizable.strings", "wb").write(fileResponse.content)
def getSpanishTranslations():
data = (
("api_token", "your_api_token"),
("id", "your_project_id"),
("language", "es"),
("type", "apple_strings"),
)
urlResponse = requests.post("https://api.poeditor.com/v2/projects/export", data=data)
values = urlResponse.json()
download_url = values["result"]["url"]
fileResponse = requests.get(download_url)
open("LocalizationTest/es.lproj/Localizable.strings", "wb").write(fileResponse.content)
def main():
getTerms()
getSpanishTranslations()
getGermanTranslations()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment