Created
March 30, 2011 09:10
-
-
Save ojii/894103 to your computer and use it in GitHub Desktop.
A python script that translates German to Swiss German
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import argparse | |
import random | |
mappings = { | |
'a': u'ä', | |
'o': u'ö', | |
'u': u'ü', | |
'k': 'ch', | |
} | |
def _swissify_single(bit, i): | |
if bit not in mappings: | |
return bit | |
choices = [bit] + [mappings[bit] for x in range(i)] | |
return random.choice(choices) | |
def swissify(value, i): | |
return ''.join([_swissify_single(bit, i) for bit in value]) | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-i', default=1, type=int) | |
parser.add_argument('data') | |
namespace = parser.parse_args() | |
print swissify(namespace.data, namespace.i) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment