Skip to content

Commit

Permalink
add python script to update l10n strings from ory/elements
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 20, 2023
1 parent f8a22a2 commit e80afba
Show file tree
Hide file tree
Showing 9 changed files with 4,829 additions and 2 deletions.
3 changes: 1 addition & 2 deletions KratosSelfService/Controllers/EntranceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public async Task<IActionResult> Recovery([FromQuery(Name = "flow")] string? flo
{
if (flowId == null)
{
var newFlow = await api.Frontend.CreateBrowserRecoveryFlowAsync();
return Redirect($"recovery?flow={newFlow.Id}");
return Redirect(api.GetUrlForFlow("recovery"));
}

KratosRecoveryFlow flow;
Expand Down
683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.de.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.en.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.es.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.fr.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.nl.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.pt.resx

Large diffs are not rendered by default.

683 changes: 683 additions & 0 deletions KratosSelfService/Resources/OryElements.se.resx

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions scripts/update_element_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import os
import json
import xml.etree.ElementTree as ElementTree
from xml.dom import minidom

supported_locales = ['de', 'en', 'es', 'fr', 'nl', 'pt', 'se']
base_url = 'https://raw.githubusercontent.com/ory/elements/main/src/locales/{locale}.json'


# Function to convert JSON to .resx format
def convert_to_resx(json_data, locale):
root = ElementTree.Element('root')

for key, value in json_data.items():
data = ElementTree.SubElement(root, 'data')
ElementTree.SubElement(data, 'value').text = value
ElementTree.SubElement(data, 'comment').text = key
data.set('name', key)
data.set('xml:space', 'preserve')

xml_string = ElementTree.tostring(root, 'utf-8')

# Format the XML string
xml_dom = minidom.parseString(xml_string)
formatted_xml = xml_dom.toprettyxml(indent=" ")

with open(f'../KratosSelfService/Resources/OryElements.{locale}.resx', 'w', encoding='utf-8') as resx_file:
resx_file.write(formatted_xml)


if __name__ == '__main__':
if not os.path.exists('Resources'):
os.makedirs('Resources')

# Iterate through supported locales and generate .resx files
for locale in supported_locales:
url = base_url.format(locale=locale)
response = requests.get(url)

if response.status_code == 200:
convert_to_resx(response.json(), locale)
print(f'Converted {locale} to .resx')
else:
print(f'Failed to fetch data for {locale}')

print('Localization update completed.')

0 comments on commit e80afba

Please sign in to comment.