How to convert English characters into Russian in Contacts?

Hi Everyone!

I need to convert English characters into Russian in Contacts. I have a few thousands of contacts in my address book. I want to change Name, Last Name and Company Name. Each character should be changed. For example, “a” changes to “а”, “b” changes to “б”, “c” changes to “к” etc. There’s a difficult story when two or three English letters translate into one Russian (i.e. “ts” should become “ц”) but I wouldn’t consider that for now and can correct that manually afterwards. I tried to do an apple script with no success as I don’t know the object names and got constant errors.

Could someone pls help me with the apple script for the task?

Regards,

Eugene.

Hi Eugene,

I think what you need to do is find the unicode numbers for this characters If you go to the utility menu and show character viewer, then you can find those numbers for your Russian equivalent. There could be many dialects I think, so there might not be one set of characters.

After you’ve found the unicode numbers, then you can use character id I think it was. Still need to test with your characters, but this might be a start unless there is a much easier way that someone knows.

gl,
kel

Here’s an example I posted in my research from another post:

set t to "б"
-- to get the unicode number
set unicode_number to id of t
--> 1073

-- to print the character
character id unicode_number
--> "б"

Edited: btw, here’s a link to more info on the extended character sets that is now unicode:
http://macscripter.net/viewtopic.php?id=43190

gl,
kel

But what should be the script itself? There should be a cycle. Something like “repeat…until”. I don’t know how to write it…

Hi Eugene,

It’s very hard to write a whole script for someone else when they have no interest in learning for their self. There is not enough info.

Good Luck and thanks,
kel

For the actual conversion, you probably need to use an ICU transform. AppleScript doesn’t support them directly, but there are two ways I know of to do it.

One is to use AppleScriptObjC and install ASObjCExtras.framework. This requires OS X 10.9 or 10.10, and the code is then:

use framework "Foundation"
use framework "ASObjCExtras"

its convertString:"AppleScriptObjC"
-->	"АпплеСцриптОбйЦ"

on convertString:theString
	return (current application's SMSFord's stringFrom:theString ICUTransform:"Latin-Cyrillic" inverse:false) as text
end convertString:

The alternative is to install Satimage.osax, and use:

its convertString:"AppleScript"
-->	"АпплеСцрипт"

on convertString:theString
	return (transform unicode theString using "Latin-Cyrillic")
end convertString:

What I was thinkinking was that Russian has many dialects as in most societies. If you want to roll your own dialoect, then there is no overall solution and you need to convert manually in a sense. Maybe I’m wrong but don’t know.

gl,
kel

yway, then you come down to translating individual characters. And that takes a long time and there is no formula.

Anyway good luck and may God bless,
kel

Thanks! There’re no dialects. The alphabet has 33 characters and I need just to substitute one by one. It looks like a cycle for every person in the Contacts, for every name, for every character in the name: if a then b, if b then c etc. logic is that simple. Just don’t want to learn Applescript to meke one small programm :slight_smile: Any help pls? :))

Hi Eugene,

Did you se my post above on unicode characters?

gl,
kel

I see what the problem is. You want to replace the characters is the text.

What you want to use is text item delimiters. It’s getting late for me, but there are many examples of replacing text. Somebody should be coming along. I’m starting to nod off already. Truly, the eyelids are very heavy.

gl,
kel

:slight_smile:

I agree with Shane, install Satimage.osax (download here: Smile companion osax) and use this script


tell application "Contacts"
	set allContacts to people
	repeat with i from 1 to count allContacts
		set currentContact to item i of allContacts
		tell currentContact
			if first name is not missing value then set first name to (my convertString:first name)
			if last name is not missing value then set last name to (my convertString:last name)
			if organization is not missing value then set organization to (my convertString:organization)
		end tell
	end repeat
	save
end tell


on convertString:theString
	return (transform unicode theString using "Latin-Cyrillic")
end convertString:

Stefan, you are the best! Thanks! :slight_smile:

I couldn’t run the script, it shows a mistake:

“Expected “,” but found identifier” for the following, highliting “unicode”:

return (transform unicode theString using “Latin-Cyrillic”)

did you install the Scripting Addition?

Hi.

It might be an idea to do this in three stages ” with two scripts:

  1. Script 1 gets the data from Contacts, does the transliterations, and displays both the originals and the transliterations in TextEdit.
  2. The user checks the results by eye and edits the transliterations (only) where necessary.
  3. Script 2 gets the edited text from TextEdit and makes the necessary alterations in Contacts.

-- Script 1: create a document in TextEdit showing four lines for each contact in Contacts:
-- 1. The contact's Contacts ID.
-- 2. The contact's [ first name ] [ last name ] [ company name ] in Latin characters ([ - ] where no name provided).
-- 3. Ditto in Cyrillic characters.
-- 4. Blank.

-- Requires the Satimage OSAX (<http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html>).

tell application "Contacts"
	--activate
	set {ids, firstNames, lastNames, organisations} to {id, first name, last name, organization} of people
end tell

-- Make a single linefeed-delimited text from the blocks of first, last, and company names.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set allNames to {firstNames, lastNames, organisations} as text
-- Replace the missing values (each coerced to "missing value" if run in Script Editor) with dashes.
set AppleScript's text item delimiters to "missing value"
set allNames to allNames's text items
set AppleScript's text item delimiters to "-"
set allNames to allNames as text

-- Created another version with Cyrillic characters.
set allNamesEdited to (transform unicode allNames using "Latin-Cyrillic") -- Requires Satimage OSAX.


-- Collate the two texts into the form to be displayed to the user.
set allNames to allNames's paragraphs
set allNamesEdited to allNamesEdited's paragraphs
set peopleCount to (count ids)
set peopleCount2 to peopleCount + peopleCount
set checkList to {}
repeat with i from 1 to (count ids)
	set end of checkList to item i of ids
	set end of checkList to "[ " & item i of allNames & " ] [ " & item (i + peopleCount) of allNames & " ] [ " & item (i + peopleCount2) of allNames & " ]"
	set end of checkList to "[ " & item i of allNamesEdited & " ] [ " & item (i + peopleCount) of allNamesEdited & " ] [ " & item (i + peopleCount2) of allNamesEdited & " ]"
	set end of checkList to ""
end repeat
set AppleScript's text item delimiters to linefeed
set checkList to checkList as text
set AppleScript's text item delimiters to astid

-- Display the text in a TextEdit document.
tell application "TextEdit"
	activate
	make new document with properties {text:checkList}
end tell

-- Script 2: To be run after the user has manually edited the document created by Script 1. Take the IDs and transliterated names from the document and set the contacts' first, last, and company names accordingly in Contacts.
-- The code setting the names in Contacts hasn't been tested for obvious reasons!

tell application "TextEdit"
	set checkList to paragraphs of (get text of document 1)
end tell

-- Parse the text from the TextEdit document.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" ] [ ", "[ ", " ]"}
repeat with i from 1 to (count checkList) by 4
	-- In each group of four paragraphs, the first contains the contact's Contacts ID and third contains the Cyrillic forms of its first, last, and company names respectively.
	set thisID to item i of checkList
	set {firstName, lastName, companyName} to text items 2 thru -2 of item (i + 2) of checkList
	
	-- Set the respective names in Contacts.
	tell application "Contacts"
		tell person id thisID
			if (firstName is not "-") then set first name to firstName
			if (lastName is not "-") then set last name to lastName
			if (companyName is not "-") then set organization to companyName
		end tell
	end tell
end repeat
set AppleScript's text item delimiters to astid

tell application "Contacts" to save

brilliant idea indeed :slight_smile:

Stefan, how to install that?

Download the package Satimage osax 3.7.0 (build 398) (link in post #13) and run the installer

Hi,

Is the Latin-Cyrillic translation in Satimage osax or any other translation 100% right? If not I was thinking about the different dialects again. then, you might want to roll your own translations.

Thinking about other languages also.

Edited: did I write this before. I know that I was thinking about it. Anyway, good luck.

gl,
kel