v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Editing Utility:Accent Removal

Jump to navigation Jump to search

Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.


The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
==Overview==
 
==Overview==
 
[[Image:Rj-unitlist.png|thumb|right|Replacing accented letters with normal ones in the raws fixes this problem.]]
 
[[Image:Rj-unitlist.png|thumb|right|Replacing accented letters with normal ones in the raws fixes this problem.]]
Some tile sets use the accented characters for additional graphical symbols. This can make racial language text difficult to read. You can remove the accented characters and symbols from the data files. This works on existing worlds and saved games.
+
Some tile sets use the accented characters for additional graphical symbols. This can make racial language test difficult to read. You can remove the accented characters and symbols from the data files. This works on existing worlds and saved games.
  
Since the structure of language files might change, it is safest if you remove the problem characters from the files yourself. Here are four methods to do just that. The first (Jackard's) only works on Windows, but is probably the easiest for novice users. The second (frobnic8's) will work anywhere Python does (i.e. just about anywhere). The third is a quick fix that works in Linux and the fourth is a small Windows application.
+
Since the structure of language files might change, it is safest if you remove the problem characters from the files yourself. Here are two methods to do just that. The first (Jackard's) only works on Windows, but is probably the easiest for novice users. The second (frobnic8's) will work anywhere Python does (i.e. just about anywhere), but requires using the command line a little.
  
 
==[[User:Jackard|Jackard]]'s [http://www.inforapid.de/html/searchreplace.htm InfoRapid] Script==  
 
==[[User:Jackard|Jackard]]'s [http://www.inforapid.de/html/searchreplace.htm InfoRapid] Script==  
Line 124: Line 124:
 
<ol>
 
<ol>
 
<li>Ensure you have [http://www.python.org Python] installed.</li>
 
<li>Ensure you have [http://www.python.org Python] installed.</li>
<li>Copy and paste code below into a file called <code>ascii_hammer.py</code> in the <code>raw/objects</code> sub-directory of your Dwarf Fortress directory. (The ASCII Hammer: Is that a name worthy of Dwarf Fortress, or what?)<p><pre>
+
<li>Copy and paste (this modified version of) "The Unicode Hammer" with the name <code>unicode_hammer.py</code> in the <code>raw/objects</code> sub-directory of your Dwarf FOrtress directory. (The Unicode Hammer: Is that a name worthy of Dwarf Fortress, or what?)<p><pre>
 
#!/usr/bin/env python
 
#!/usr/bin/env python
"""Convert Dwarf Fortress Language files from extended ascii to
+
"""
unaccented ascii. Based on the unicode hammer from:
+
latin1_to_ascii -- The UNICODE Hammer -- AKA "The Stupid American"
http://code.activestate.com/recipes/251871-latin1-to-ascii-the-unicode-hammer/
+
 
 +
This takes a UNICODE string and replaces Latin-1 characters with
 +
something equivalent in 7-bit ASCII. This returns a plain ASCII string.
 +
This function makes a best effort to convert Latin-1 characters into
 +
ASCII equivalents. It does not just strip out the Latin1 characters.
 +
All characters in the standard 7-bit ASCII range are preserved.
 +
In the 8th bit range all the Latin-1 accented letters are converted to  
 +
unaccented equivalents. Most symbol characters are converted to
 +
something meaningful. Anything not converted is deleted.
 +
 
 +
Background:
 +
 
 +
One of my clients gets address data from Europe, but most of their systems
 +
cannot handle Latin-1 characters. With all due respect to the umlaut,
 +
scharfes s, cedilla, and all the other fine accented characters of Europe,
 +
all I needed to do was to prepare addresses for a shipping system.
 +
After getting headaches trying to deal with this problem using Python's
 +
built-in UNICODE support I gave up and decided to use some brute force.
 +
This function converts all accented letters to their unaccented equivalents.
 +
I realize this is dirty, but for my purposes the mail gets delivered.
  
by frobnic8
+
Noah Spurrier noah at noah.org
 +
License free and public domain
 
"""
 
"""
  
 +
"""This version has had its translation table abused to produce
 +
better results for the language files of the game Dwarf Fortress by
 +
frobnic8. The original translation table is commented out.
 +
"""
  
from glob import glob
+
def latin1_to_ascii (unicrap):
from shutil import move
 
 
 
def latin1_to_ascii(unicrap):
 
 
     """This takes a UNICODE string and replaces Latin-1 characters with
 
     """This takes a UNICODE string and replaces Latin-1 characters with
 
     something equivalent in 7-bit ASCII. It returns a plain ASCII string.
 
     something equivalent in 7-bit ASCII. It returns a plain ASCII string.
Line 147: Line 168:
 
     something meaningful. Anything not converted is deleted.
 
     something meaningful. Anything not converted is deleted.
 
     """
 
     """
     xlate = {
+
     xlate={0xc0:'A', 0xc1:'A', 0xc2:'A', 0xc3:'A', 0xc4:'A', 0xc5:'A',
            0x80: 'C',
+
        0xc6:'Ae', 0xc7:'C',
            0x81: 'u',
+
        0xc8:'E', 0xc9:'E', 0xca:'E', 0xcb:'E',
            0x82: 'e',
+
        0xcc:'I', 0xcd:'I', 0xce:'I', 0xcf:'I',
            0x83: 'a',
+
        0xd0:'Th', 0xd1:'N',
            0x84: 'a',
+
        0xd2:'O', 0xd3:'O', 0xd4:'O', 0xd5:'O', 0xd6:'O', 0xd8:'O',
            0x85: 'a',
+
        0xd9:'U', 0xda:'U', 0xdb:'U', 0xdc:'U',
            0x86: 'a',
+
        0xdd:'Y', 0xde:'th', 0xdf:'ss',
            0x87: 'c',
+
        0xe0:'a', 0xe1:'a', 0xe2:'a', 0xe3:'a', 0xe4:'a', 0xe5:'a',
            0x88: 'e',
+
        0xe6:'ae', 0xe7:'c',
            0x89: 'e',
+
        0xe8:'e', 0xe9:'e', 0xea:'e', 0xeb:'e',
            0x8a: 'e',
+
        0xec:'i', 0xed:'i', 0xee:'i', 0xef:'i',
            0x8b: 'i',
+
        0xf0:'th', 0xf1:'n',
            0x8c: 'i',
+
        0xf2:'o', 0xf3:'o', 0xf4:'o', 0xf5:'o', 0xf6:'o', 0xf8:'o',
            0x8d: 'i',
+
        0xf9:'u', 0xfa:'u', 0xfb:'u', 0xfc:'u',
            0x8e: 'A',
+
        0xfd:'y', 0xfe:'th', 0xff:'y',
            0x8f: 'A',
+
        0xa1:'aa', 0xa2:'cz', 0xa3:'ii', 0xa4:'tz',
            0x90: 'E',
+
        0xa5:'yy', 0xa6:'|', 0xa7:'zz', 0xa8:'"',
            0x91: 'ae',
+
        0xa9:'CC', 0xaa:'aa', 0xab:'<<', 0xac:'not',
            0x92: "AE",
+
        0xad:'-', 0xae:'{R}', 0xaf:'_', 0xb0:'o',
            0x93: 'o',
+
        0xb1:'+/-', 0xb2:'^2', 0xb3:'^3', 0xb4:"'",
            0x94: "o",
+
        0xb5:'uu', 0xb6:'PP', 0xb7:'*', 0xb8:',,',
            0x95: 'o',
+
        0xb9:'^1', 0xba:'^o', 0xbb:'>>',
            0x96: 'u',
+
        0xbc:'1/4', 0xbd:'1/2', 0xbe:'3/4', 0xbf:'?',
            0x97: 'u',
+
        0xd7:'*', 0xf7:'/'
            0x98: 'y',
+
    }
            0x99: 'O',
+
    """ Orignals below, the above is hacked for Dwarf Fortress languages.
            0x9a: 'U',
+
        0xa1:'!', 0xa2:'{cent}', 0xa3:'{pound}', 0xa4:'{currency}',
            0x9b: 'c',
+
        0xa5:'{yen}', 0xa6:'|', 0xa7:'{section}', 0xa8:'{umlaut}',
            0x9c: 'E',
+
        0xa9:'{C}', 0xaa:'{^a}', 0xab:'<<', 0xac:'{not}',
            0x9d: 'Y',
+
        0xad:'-', 0xae:'{R}', 0xaf:'_', 0xb0:'{degrees}',
            0x9e: 'P',
+
        0xb1:'{+/-}', 0xb2:'{^2}', 0xb3:'{^3}', 0xb4:"'",
            0x9f: 'f',
+
        0xb5:'{micro}', 0xb6:'{paragraph}', 0xb7:'*', 0xb8:'{cedilla}',
            0xa0: 'a',
+
        0xb9:'{^1}', 0xba:'{^o}', 0xbb:'>>',
            0xa1: 'i',
+
        0xbc:'{1/4}', 0xbd:'{1/2}', 0xbe:'{3/4}', 0xbf:'?',
            0xa2: 'o',
+
        0xd7:'*', 0xf7:'/'
            0xa3: 'u',
+
    }
            0xa4: 'n',
+
    """
            0xa5: 'N',
 
            0xa6: 'a',
 
            0xa7: 'o',
 
            0xa8: 'b',
 
            0xa9: 'r',
 
            0xaa: 'n',
 
            0xab: '1/2',
 
            0xac: '1/4',
 
            0xad: 'i',
 
            0xae: '<<',
 
            0xaf: '>>',
 
            0xe0: 'a',
 
            0xe1: 'B',
 
            0xe2: 't',
 
            0xe3: 'n',
 
            0xe4: 'E',
 
            0xe5: 'o',
 
            0xe6: 'u',
 
            0xe7: 't',
 
            0xe8: 'o',
 
            0xe9: 'o',
 
            0xea: 'o',
 
            0xeb: 'o',
 
            0xec: 'oo',
 
            0xed: 'o',
 
            0xee: 'e',
 
            0xef: 'N',
 
            0xf0: 'E',
 
            0xf1: 't',
 
            0xf2: 'D',
 
            0xf3: 'k',
 
            0xf4: 'f',
 
            0xf5: 'j',
 
            0xf6: 'i',
 
            0xf7: 'e',
 
            0xf8: 'o',
 
            0xf9: 'o',
 
            0xfa: 'i',
 
            0xfb: 'v',
 
            0xfc: 'n',
 
            0xfd: 'z',
 
            }
 
 
 
 
 
 
     r = ''
 
     r = ''
 
     for i in unicrap:
 
     for i in unicrap:
Line 240: Line 217:
  
 
if __name__ == '__main__':
 
if __name__ == '__main__':
     for lang in glob('language_*'):
+
     import sys
         source = open(lang)
+
    input = sys.stdin
         dest = open('tmp_' + lang, 'w')
+
    output = sys.stdout
         for line in source:
+
    if len(sys.argv) == 1 or (len(sys.argv) == 2 and \
             dest.write(latin1_to_ascii(line))
+
      sys.argv[1] in ('-h', '-H', '-?', '--help', '/?', '/H', '/h')):
         source.close()
+
         print 'unicode_hammer.py [infile [outfile]]\n'
         dest.close()
+
         s = unicode('','latin-1')
move(lang, 'orig_' + lang)
+
         for c in range(32, 256):
         move('tmp_' + lang, lang)
+
             if c != 0x7f:
 +
                s += unicode(chr(c), 'latin-1')
 +
            plain_ascii = latin1_to_ascii(s)
 +
 
 +
        print 'INPUT type:', type(s)
 +
        print 'INPUT:'
 +
        print s.encode('latin-1')
 +
        print
 +
        print 'OUTPUT type:', type(plain_ascii)
 +
         print 'OUTPUT:'
 +
        print plain_ascii
 +
        sys.exit()
 +
 
 +
    if len(sys.argv) > 1:
 +
         input = open(sys.argv[1])
 +
    if len(sys.argv) > 2:
 +
        output = open(sys.argv[2], 'w')
 +
    for line in input:
 +
         output.write(latin1_to_ascii(line))
  
 
</pre></p></li>
 
</pre></p></li>
<li>Double click on the <code>ascii_hammer.py</code> file in the folder.
+
<li>Open a command prompt and change directory to your <code>raw/objects</code> directory.</li>
 +
<li>Rename the four language files, adding '.orig' to the end of their names:<p><pre>
 +
mv language_DWARF.txt language_DWARF.txt.orig
 +
mv language_ELF.txt language_ELF.txt.orig
 +
mv language_GOBLIN.txt language_GOBLIN.txt.orig
 +
mv language_HUMAN.txt language_HUMAN.txt.orig
 +
</pre></p></li>
 +
<li>Apply the hammer to each of the four language files as follows:<p><pre>
 +
python unicode_hammer.py language_DWARF.txt.orig language_DWARF.txt
 +
python unicode_hammer.py language_ELF.txt.orig language_ELF.txt
 +
python unicode_hammer.py language_GOBLIN.txt.orig language_GOBLIN.txt
 +
python unicode_hammer.py language_HUMAN.txt.orig language_HUMAN.txt
 +
</pre></p></li>
 
<li>Enjoy!</li>
 
<li>Enjoy!</li>
 
</ol>
 
</ol>
 
== The Linux way ==
 
 
Conversion between character sets is a standard part of Linux.  To convert all the files in one go, change to the "raw/objects" directory and run this command:
 
 
for f in language_*.txt; do \
 
  iconv -f CP437 -t ASCII//TRANSLIT $f > $f.new; \
 
  mv -fv $f.new $f; \
 
done
 
 
All accented characters are converted to their normal, non-accented versions.  Other characters (if any) are converted to their closest 7-bit ASCII representation.
 
 
This will overwrite the original language files.  If you want them back, you can always unzip them again:
 
 
unzip -j '''''path-to-zipfile''''' raw/objects/language_\*.txt
 
 
== [[User:Hermano|Hermano]]s small app ==
 
 
For Windows users there is this small [http://dffd.wimbli.com/file.php?id=2088 application] that replaces accented characters from files by just dragging & dropping the file on the application icon.
 
 
[[category:Utility:Outdated]]
 

Please note that all contributions to Dwarf Fortress Wiki are considered to be released under the GFDL & MIT (see Dwarf Fortress Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)