Updated jstring_convert helper. Now using for displaying KD2 readings.
[jben2_gui.git] / jbparse / jbparse / kanjidic_common.py
blob1f085b6b6fd9529bb6fbf8ecab7d1df7d3904e8d
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2009, Paul Goins
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
30 """Helper functions for KANJIDIC and KANJIDIC2 parsers.
32 This module is not intended to be used by itself.
34 """
36 def jstring_convert(s):
37 """Convert's from Jim Breen's -x.xx- notation to 〜x(xx)〜 notation."""
38 s = s.replace(u'-', u'〜')
39 parts = s.split(u'.', 1)
40 if len(parts) == 1:
41 return s
42 return u"%s(%s)" % tuple(parts)
44 def kanjidic2_key_to_str(dkey):
45 """Converts KANJIDIC2 dictionary keys to dictionary names.
47 If unable to find a KANJIDIC2 key, returns the original key.
49 """
50 d = {
51 "halpern_njecd":
52 _(u"New Japanese-English Character Dictionary (Halpern)"),
53 "nelson_c":
54 _(u"Modern Reader's Japanese-English Character Dictionary (Nelson)"),
55 "nelson_n":
56 _(u"The New Nelson Japanese-English Character Dictionary (Haig)"),
57 "sh_kk": _(u"Kanji and Kana (Spahn/Hadamitzky)"),
58 "moro": _(u"Morohashi Daikanwajiten"),
59 "henshall":
60 _(u"A Guide To Remembering Japanese Characters (Henshall)"),
61 "gakken": _(u"A New Dictionary of Kanji Usage (Gakken)"),
62 "heisig": _(u"Remembering the Kanji (Heisig)"),
63 "oneill_names": _(u"Japanese Names (O'Neill)"),
64 "busy_people": _(u"Japanese For Busy People (AJLT)"),
65 "crowley": _(u"The Kanji Way to Japanese Language Power (Crowley)"),
66 "jf_cards": _(u"Japanese Kanji Flashcards (Hodges/Okazaki)"),
67 "kodansha_compact": _(u"Kodansha Compact Kanji Guide"),
68 "henshall3": _(u"A Guide To Reading and Writing Japanese (Henshall)"),
69 "kanji_in_context": _(u"Kanji in Context (Nishiguchi/Kono)"),
70 "halpern_kkld": _(u"Kodansha Kanji Learners Dictionary (Halpern)"),
71 "oneill_kk": _(u"Essential Kanji (O'Neill)"),
72 "sakade": _(u"A Guide To Reading and Writing Japanese (Sakade)"),
73 "tutt_cards": _(u"Tuttle Kanji Cards (Kask)"),
74 "maniette": _(u"French version of Heisig (Maniette)")
76 return d.get(dkey, dkey)
78 def qcode_to_desc(qkey):
79 d = {
80 u'skip': u'SKIP',
81 u'deroo': u'De Roo',
82 u'sh_desc': u'Spahn/Hadamitzky Kanji Dictionary',
83 u'four_corner': u'Four Corner'
85 return d.get(qkey, qkey)