Mathias,

It would be way simpler to just use the "Find and Replace" window using the 
below regular expressions and replacement strings.

In the find window check the "Grep" and  "Wrap around" checkboxes and leave 
the other checkboxes unchecked.

If it works for your purpose in the "Find" window, you can then automate 
the process with a "Replace All" text factory: File menu > New > Text 
Factory.

*From double quotes -> tags:*

Find:

^\h*["”]((?:[^"”\\]|\\.)+?)["”]\h*=\h*["”]([^"”]+)[”"]\h*;\h*$

Replace:

<string name="\1">\2</string>


*From tags -> double quotes:*

Find:

^\h*<string\h+name\h*=\h*[”"]((?:[^"”\\]|\\.)+?)[”"]>([^<]+)</string>\h*$

Replace:

"\1" = "\2";

The regular expressions are a bit complicated because they handle the 
different type of quotations marks used in your example and the case of 
escaped quotes in the strings.

If you have escaped quotes (\") in your strings, think to convert them to 
html entities (&quot;) in your tag version.

HTH

Jean Jourdain


On Tuesday, October 13, 2020 at 2:12:33 PM UTC+2 Mathias wrote:

> Hi there,
> i'm trying to make 2 scripts to convert between IOS and Android i18n 
> formats to work. I've gotten Android -> IOS to work, but the other way 
> around is a challenge.
>
> Basically, for each row in a file i want to convert
> *"login_infoLabel" = "Do you need help? Press here.”;*
> to
> *<string name="login_infoLabel">Do you need help? Press here.</string*
>
> See my script below. The problem is the first search string to find the 
> first " on each row. I spoke with Patrik at BBEdit and he kindly informed 
> me that it was because AppleScript doesn't support grep and that i should 
> instead record my replace with the script editor. 
>
> I did that, but now i'm at a loss as to how combine these two snippets, 
> where one is apple script and one is not?
>
> Also, the 'record' contains the actual file name, how do i make the script 
> just use the file showing in the window as i do with the apple script?
>
> If anyone could point me in the right direction, i'd be most thankful.
>
> *My replace "recording":*
> replace "^\"" using "<string name=\\\"" searching in text 1 of text 
> document "untitled text 133" options {search mode:grep, starting at 
> top:true}
>
>
> *My Apple script (the first item in search_strings is what won't work):*
> set search_strings to {*"^\""*, "\" = \"", "\";"}
> set replace_strings to {"<string name=\"", "\">", "</string>"}
>
> tell application "BBEdit"
> set the_string to (selection of front window as string)
> repeat with i from 1 to (count search_strings)
> set the_string to my snr(the_string, item i of search_strings, item i of 
> replace_strings)
> end repeat
> --set the clipboard to the_string
> set selection of front window to the_string
> end tell
>
> on snr(the_string, search_string, replace_string)
> tell (a reference to my text item delimiters)
> set {old_atid, contents} to {contents, search_string}
> set {the_string, contents} to {the_string's text items, replace_string}
> set {the_string, contents} to {"" & the_string, old_atid}
> end tell
> return the_string
> end snr
>
> The 'record' from BBEdit:
>
>

-- 
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/5e48a47b-282e-4ce8-9976-a871696708b5n%40googlegroups.com.

Reply via email to