Last active
September 6, 2018 12:48
-
-
Save bezysoftware/3a2b262354a27e7d86016563f82aaea8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function Convert-StringsToResX([string] $strings) | |
| { | |
| [xml]$xml = Get-Content -Path $strings -Encoding UTF8 | |
| Write-ResXHeader | |
| # android strings | |
| $nodes = $xml.SelectNodes("/resources/string") | |
| foreach ($node in $nodes) | |
| { | |
| $value = $node.InnerXml | |
| Write-ResXItem $node.name $value | |
| } | |
| # android strings plurals | |
| $nodes = $xml.SelectNodes("/resources/plurals") | |
| foreach ($node in $nodes) | |
| { | |
| foreach ($item in $node.SelectNodes("item")) | |
| { | |
| $value = $item.InnerXml | |
| Write-ResXItem "$($node.name)_$($item.quantity)" $value | |
| } | |
| } | |
| Write-ResXFooter | |
| } | |
| function Write-ResXItem([string] $name, [string] $value) | |
| { | |
| # replace invalid characters and string interpolations into C# format | |
| $text = $value -replace "…", "…" -replace "&","&" -replace "\\'", "'" -replace "%%", "%" -replace '’', "'" -replace '–', '-' -replace '%s', '{0}' -replace '%d', '{0}' -replace '%1\$s', '{0}' -replace '%2\$s', '{1}' -replace '%3\$s','{2}' -replace '%1\$d', '{0}' -replace '%2\$d', '{1}' -replace '\\n',"`n" | |
| # replace Play references to Store. E.g. 'Rate us in Google Play' becomes 'Rate us in Microsoft Store' | |
| $text = $text -replace "Google Play", 'Microsoft Store' | |
| $startData = '' | |
| $endData = '' | |
| # wrap the phrase in CDATA container, unless it is already wrapped | |
| if (-Not($text.StartsWith('<![CDATA['))) { | |
| $startData = '<![CDATA[' | |
| $endData = ']]>' | |
| } | |
| Write-Output " <data name=`"$name`" xml:space=`"preserve`"> | |
| <value>$startData$text$endData</value> | |
| </data>" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment