Created
May 24, 2024 09:39
-
-
Save rsoeteman/9c8e5a9c365cba3b925b2f5088bdf27e to your computer and use it in GitHub Desktop.
Powershell script to convert backoffice language file to typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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