On 12/15/2020, at 00:42, Mathias <[email protected]
<mailto:[email protected]>> wrote:
> Below are three example rows the way they work on Android, followed by their
> equivalent IOS counterparts.
>
> <string name="switch_header">Switch account</string>
> <string name="automaticCheckinTo">Automatic check-in to %1$s</string>
> <string name="shortcut_subtitle_checkin">Choose location</string>
>
>
> "switch_header" = "Switch account";
> "automaticCheckinTo" = "Automatic check-in to %@";
> "shortcut_subtitle_checkin" = "Choose location";
Hey Mathias,
Okay, that helps.
Let's start with AppleScript, since that's the way you began yourself.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2020/12/17 00:01
# dMod: 2020/12/17 00:01
# Appl: BBEdit
# Task: Android Strings to Equivalent iOS Strings.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Android, @IOS, @RegEx
--------------------------------------------------------
tell application "BBEdit"
tell front text window
replace "<string name=(\"[^\"]+?\")>([^<]+?)</string>" using "\\1 =
\"\\2\";" options ¬
{search mode:grep, case sensitive:false, starting at top:true}
replace "%1$s" using "%@" options {case sensitive:false, starting at
top:true}
end tell
end tell
--------------------------------------------------------
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2020/12/17 00:01
# dMod: 2020/12/17 00:03
# Appl: BBEdit
# Task: iOS Strings to Equivalent Android Strings.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Android, @IOS, @RegEx
--------------------------------------------------------
tell application "BBEdit"
tell front text window
replace "(\"[^\"]+?\") = \"([^\"]+?)\";" using "<string
name=\\1>\\2</string>" options ¬
{search mode:grep, case sensitive:false, starting at top:true} --
RegEx replacement.
replace "%@" using "%1$s" options {case sensitive:false, starting at
top:true} -- Literal replacement.
end tell
end tell
--------------------------------------------------------
Now let's attempt some Perl:
#!/usr/bin/env perl -0777 -nw
# --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2020/12/17 00:20
# dMod: 2020/12/17 00:21
# Task: Android Strings to Equivalent iOS Strings.
# Tags: @ccstone, @Shell, @Script, @Android, @iOS, @Perl
# --------------------------------------------------------
s!<string name=("[^"]+?")>([^<]+?)</string>!$1 = "$2";!ig;
s!%1\$s!%@!ig;
print;
# --------------------------------------------------------
#!/usr/bin/env perl -0777 -nw
# --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2020/12/17 00:20
# dMod: 2020/12/17 00:28
# Task: iOS Strings to Equivalent Android Strings.
# Tags: @ccstone, @Shell, @Script, @Android, @iOS, @Perl
# --------------------------------------------------------
s!("[^"]+?") = "([^"]+?)";!<string name=$1>$2</string>!ig;
s!%@!%1\$s!ig;
print;
# --------------------------------------------------------
In this case I'm scarfing up the whole file before doing the search/replace.
If the file was really big I'd iterate through the lines in a while loop.
Now for giggles let's trot out sed:
#!/usr/bin/env bash
# --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2020/12/17 01:05
# Task: Android Strings to Equivalent iOS Strings.
# Tags: @ccstone, @Shell, @Script, @Android, @iOS, @sed
# --------------------------------------------------------
sed -En '
s!<string name=("[^"]+")>([^<]+)</string>!\1 = "\2";!
s!%1\$s!%@!
p
'
# --------------------------------------------------------
#!/usr/bin/env bash
# --------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2012/11/27 08:12
# dMod: 2020/12/17 00:53
# Task: iOS Strings to Equivalent Android Strings.
# Tags: @ccstone, @Shell, @Script, @Android, @iOS, @sed
# --------------------------------------------------------
sed -En '
s!("[^"]+") = "([^"]+)";!<string name=\1>\2</string>!
s!%@!%1$s!
p
'
# --------------------------------------------------------
Let me know if you have any problems.
--
Best Regards,
Chris
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/DDF7E0ED-9E58-443D-9059-D0F9892A03D4%40gmail.com.