1 |
|
# Orca |
2 |
|
# |
3 |
|
# Copyright 2006-2007 Sun Microsystems Inc. |
4 |
|
# |
5 |
|
# This library is free software; you can redistribute it and/or |
6 |
|
# modify it under the terms of the GNU Library General Public |
7 |
|
# License as published by the Free Software Foundation; either |
8 |
|
# version 2 of the License, or (at your option) any later version. |
9 |
|
# |
10 |
|
# This library is distributed in the hope that it will be useful, |
11 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
|
# Library General Public License for more details. |
14 |
|
# |
15 |
|
# You should have received a copy of the GNU Library General Public |
16 |
|
# License along with this library; if not, write to the |
17 |
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
# Boston, MA 02111-1307, USA. |
19 |
|
|
20 |
|
"""Provides getPhoneticName method that maps each letter of the |
21 |
1 |
alphabet into its localized phonetic equivalent.""" |
22 |
|
|
23 |
1 |
__id__ = "$Id: phonnames.py 2295 2007-04-18 12:56:34Z wwalker $" |
24 |
1 |
__version__ = "$Revision: 2295 $" |
25 |
1 |
__date__ = "$Date: 2007-04-18 08:56:34 -0400 (Wed, 18 Apr 2007) $" |
26 |
1 |
__copyright__ = "Copyright (c) 2006-2007 Sun Microsystems Inc." |
27 |
1 |
__license__ = "LGPL" |
28 |
|
|
29 |
1 |
from orca_i18n import _ # for gettext support |
30 |
|
|
31 |
|
# Translators: this is a structure to assist in the generation of |
32 |
|
# spoken military-style spelling. For example, 'abc' becomes 'alpha |
33 |
|
# bravo charlie'. |
34 |
|
# |
35 |
|
# It is a simple structure that consists of pairs of |
36 |
|
# |
37 |
|
# letter : word(s) |
38 |
|
# |
39 |
|
# where the letter and word(s) are separate by colons and each |
40 |
|
# pair is separated by commas. For example, we see: |
41 |
|
# |
42 |
|
# a : alpha, b : bravo, c : charlie, |
43 |
|
# |
44 |
|
# And so on. The complete set should consist of all the letters from |
45 |
|
# the alphabet for your language paired with the common |
46 |
|
# military/phonetic word(s) used to describe that letter. |
47 |
|
# |
48 |
|
# The Wikipedia entry |
49 |
|
# http://en.wikipedia.org/wiki/NATO_phonetic_alphabet has a few |
50 |
|
# interesting tidbits about local conventions in the sections |
51 |
|
# "Additions in German, Danish and Norwegian" and "Variants". |
52 |
|
# |
53 |
1 |
__phonlist = _("a : alpha, b : bravo, c : charlie, " |
54 |
|
"d : delta, e : echo, f : foxtrot, " |
55 |
|
"g : golf, h : hotel, i : india, " |
56 |
|
"j : juliet, k : kilo, l : lima, " |
57 |
|
"m : mike, n : november, o : oscar, " |
58 |
|
"p : papa, q : quebec, r : romeo, " |
59 |
|
"s : sierra, t : tango, u : uniform, " |
60 |
|
"v : victor, w : whiskey, x : xray, " |
61 |
|
"y : yankee, z : zulu") |
62 |
|
|
63 |
1 |
__phonnames = {} |
64 |
|
|
65 |
27 |
for __pair in __phonlist.split(','): |
66 |
26 |
__w = __pair.split(':') |
67 |
26 |
__phonnames [__w[0].strip()] = __w[1].strip() |
68 |
|
|
69 |
1 |
def getPhoneticName(character): |
70 |
|
"""Given a character, return its phonetic name, which is typically |
71 |
|
the 'military' term used for the character. |
72 |
|
|
73 |
|
Arguments: |
74 |
|
- character: the character to get the military name for |
75 |
|
|
76 |
|
Returns a string representing the military name for the character |
77 |
|
""" |
78 |
|
|
79 |
0 |
if isinstance(character, unicode): |
80 |
0 |
character = character.encode("UTF-8") |
81 |
|
|
82 |
0 |
try: |
83 |
0 |
return __phonnames[character] |
84 |
0 |
except: |
85 |
0 |
return character |