Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rsoeteman/9c8e5a9c365cba3b925b2f5088bdf27e to your computer and use it in GitHub Desktop.
Save rsoeteman/9c8e5a9c365cba3b925b2f5088bdf27e to your computer and use it in GitHub Desktop.
Powershell script to convert backoffice language file to typescript
# Load the XML file
[xml]$xml = Get-Content 'en-US.xml'
# Initialize the output object
$output = @{}
# Iterate over each 'area' node
foreach ($area in $xml.language.ChildNodes) {
# Ignore 'language' and 'creator' nodes
if ($area.Name -eq 'language' -or $area.Name -eq 'creator') {
continue
}
# Create a new property for the area
$areaName = $area.alias
if ($null -ne $areaName) {
$output[$areaName] = @{}
# Iterate over each 'key' node in the area
foreach ($key in $area.ChildNodes) {
# Create a new property for the key
$keyName = $key.alias
if ($null -ne $keyName) {
$output[$areaName][$keyName] = $key.'#text'
}
}
}
}
# Convert the output object to JSON
$json = ConvertTo-Json $output -Depth 100
# Add "export default" at the beginning of the JSON string
$json = "export default " + $json
# Save the JSON to a file
$json | Out-File 'output.ts' -Encoding Default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment