#!/usr/bin/python # -*- coding: UTF-8 -*- ## locale-decode.py - Contains the script for converting locale file string in readable format ## Copyright (C) 2009 Red Hat, Inc. ## Copyright (C) 2009 Pravin Satpute ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # Usage: Example # $ python locale-decode.py /usr/share/i18n/locale/hi_IN # $ vi hi_IN_Converted import os, sys import string def convert(ip, op): ipfile = open(ip) fout = open(op, 'w') flines = ipfile.readlines() linecount = len(flines) for l in flines: w = l.split() for i in range( len(w)): fout.write(w[i]) fout.write(" ") if len(w[i]) >= 2: if (((w[i][1]) == "<") |((w[i][0]) == "<")): neword = w[1:len(w[i])-1] if len(neword)==0: neword = w[0:len(w[i])-1] process_word(neword, fout) fout.write("\n") def process_word(word, fout): if len(word) > 0: for i in range (len(word[0])): if(word[0][i]=='<'): hexstr = word[0][i+2:i+6] print_char(hexstr, fout) def print_char(hexstr2, fout): char = unichr(string.atoi(hexstr2, 16)) fout.write(char.encode("UTF-8")) if __name__ == "__main__": try: ipfile = sys.argv[1] outfile = ipfile + '_converted' convert(ipfile,outfile) except: print "# Usage: Example" print "$python locale-decode.py /usr/share/i18n/locale/hi_IN" print "$vi hi_IN_Converted"