#! /usr/bin/env python
#
#This script creates text files containing translated timezone names.
#These text files are loaded by oem-config at statup and populate
#langauge-specific data models. Whent he user picks the language on
#step one of oem-config, the data model used by the combobox on step three, 
#one of the two ways the user has of picking their locations, is switched. 
#Result: cities are translated to the current langauge selection.
#
#This file is used before build time only to create needed files:
#
#How To:
#Install oem-translations package on your build system (it contains 
#translations used by this script).
#Run this script to produce text files needed for data models
#Ensure these text files are installed with oem-config. 
#oem-translations, this file, and zoommap.py have to support the same locales.


import datetime
import sys
import gobject
import pango
import gtk
import gettext
from math import pi
import subprocess

import lib.tz

tzdb = lib.tz.Database()

locales = ["de_DE.UTF-8", \
"en_US.UTF-8", \
"es_ES.UTF-8", \
"fr_FR.UTF-8", \
"it_IT.UTF-8", \
"ja_JP.UTF-8", \
"ko_KR.UTF-8", \
"ru_RU.UTF-8", \
"zh_CN.UTF-8", \
"zh_TW.UTF-8", \
]

class HotSpot:
    def __init__(self, tz, x, y, parent):
        self.tz = tz
        self.x = float(x)
        self.y = float(y)
        self.selected = False
        # FIXME evand 2008-02-18: something a bit more accurate.
        self.width, self.height = (50, 50)

prev_continent = ''
hotspots = []

for lang_code in locales:

    file_name = "./locale_data_models/" + lang_code + "_model"

    f = open(file_name, "w")

    for location in tzdb.locations:
        # Convert longitude and latitude to percentages of total width and
        # length.
        x = (location.longitude + 180) / 360
        y = 1 - ((location.latitude + 90) / 180)
        hotspot = HotSpot(location, x, y, parent=None)
        hotspots.append(hotspot)

        zone_bits = location.zone.split('/')
        if len(zone_bits) == 1:
            continue
        continent = zone_bits[0]

        if continent != prev_continent:
            f.write("\n")
            f.write("---" + continent + " ---\n")
        prev_continent = continent
        human_zone = '/'.join(zone_bits[1:]).replace('_', ' ')

        city_trans = subprocess.Popen(["gettext", "-d" , "oem-translations", \
            human_zone], env={"LANG": lang_code}, stdout=subprocess.PIPE).communicate()[0]
        f.write(str(human_zone) + "," + str(location.zone) + "," + str(city_trans) + "\n")

    print "file: '" + file_name + "' created"

    f.flush()
    f.close()


