objdictgen/i18n/mki18n.py
author Edouard Tisserant
Thu, 24 Jan 2019 13:49:40 +0100
changeset 807 46027bb24429
parent 580 2ae92a99ac10
permissions -rw-r--r--
Rewrite of timer_xeno.c to use POSIX API instead of Alchemy.
580
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     1
#! /usr/bin/env python
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     2
# -*- coding: iso-8859-1 -*-
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     3
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     4
#   PYTHON MODULE:     MKI18N.PY
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     5
#                      =========
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     6
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     7
#   Abstract:         Make Internationalization (i18n) files for an application.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     8
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
     9
#   Copyright Pierre Rouleau. 2003. Released to public domain.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    10
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    11
#   Last update: Saturday, November 8, 2003. @ 15:55:18.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    12
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    13
#   File: ROUP2003N01::C:/dev/python/mki18n.py
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    14
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    15
#   RCS $Header: //software/official/MKS/MKS_SI/TV_NT/dev/Python/rcs/mki18n.py 1.5 2003/11/05 19:40:04 PRouleau Exp $
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    16
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    17
#   Update history:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    18
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    19
#   - File created: Saturday, June 7, 2003. by Pierre Rouleau
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    20
#   - 10/06/03 rcs : RCS Revision 1.1  2003/06/10 10:06:12  PRouleau
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    21
#   - 10/06/03 rcs : RCS Initial revision
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    22
#   - 23/08/03 rcs : RCS Revision 1.2  2003/06/10 10:54:27  PRouleau
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    23
#   - 23/08/03 P.R.: [code:fix] : The strings encoded in this file are encode in iso-8859-1 format.  Added the encoding
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    24
#                    notification to Python to comply with Python's 2.3 PEP 263.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    25
#   - 23/08/03 P.R.: [feature:new] : Added the '-e' switch which is used to force the creation of the empty English .mo file.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    26
#   - 22/10/03 P.R.: [code] : incorporated utility functions in here to make script self sufficient.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    27
#   - 05/11/03 rcs : RCS Revision 1.4  2003/10/22 06:39:31  PRouleau
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    28
#   - 05/11/03 P.R.: [code:fix] : included the unixpath() in this file.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    29
#   - 08/11/03 rcs : RCS Revision 1.5  2003/11/05 19:40:04  PRouleau
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    30
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    31
#   RCS $Log: $
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    32
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    33
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    34
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    35
"""                                
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    36
mki18n allows you to internationalize your software.  You can use it to 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    37
create the GNU .po files (Portable Object) and the compiled .mo files
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    38
(Machine Object).
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    39
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    40
mki18n module can be used from the command line or from within a script (see 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    41
the Usage at the end of this page).
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    42
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    43
    Table of Contents
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    44
    -----------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    45
    
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    46
    makePO()             -- Build the Portable Object file for the application --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    47
    catPO()              -- Concatenate one or several PO files with the application domain files. --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    48
    makeMO()             -- Compile the Portable Object files into the Machine Object stored in the right location. --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    49
    printUsage           -- Displays how to use this script from the command line --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    50
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    51
    Scriptexecution      -- Runs when invoked from the command line --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    52
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    53
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    54
NOTE:  this module uses GNU gettext utilities.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    55
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    56
You can get the gettext tools from the following sites:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    57
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    58
   - `GNU FTP site for gettetx`_ where several versions (0.10.40, 0.11.2, 0.11.5 and 0.12.1) are available.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    59
     Note  that you need to use `GNU libiconv`_ to use this. Get it from the `GNU
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    60
     libiconv  ftp site`_ and get version 1.9.1 or later. Get the Windows .ZIP
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    61
     files and install the packages inside c:/gnu. All binaries will be stored
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    62
     inside  c:/gnu/bin.  Just  put c:/gnu/bin inside your PATH. You will need
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    63
     the following files: 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    64
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    65
      - `gettext-runtime-0.12.1.bin.woe32.zip`_ 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    66
      - `gettext-tools-0.12.1.bin.woe32.zip`_
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    67
      - `libiconv-1.9.1.bin.woe32.zip`_ 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    68
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    69
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    70
.. _GNU libiconv:                            http://www.gnu.org/software/libiconv/
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    71
.. _GNU libiconv ftp site:                   http://www.ibiblio.org/pub/gnu/libiconv/
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    72
.. _gettext-runtime-0.12.1.bin.woe32.zip:    ftp://ftp.gnu.org/gnu/gettext/gettext-runtime-0.12.1.bin.woe32.zip           
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    73
.. _gettext-tools-0.12.1.bin.woe32.zip:      ftp://ftp.gnu.org/gnu/gettext/gettext-tools-0.12.1.bin.woe32.zip 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    74
.. _libiconv-1.9.1.bin.woe32.zip:            http://www.ibiblio.org/pub/gnu/libiconv/libiconv-1.9.1.bin.woe32.zip
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    75
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    76
"""
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    77
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    78
# Module Import
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    79
# -------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    80
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    81
import os
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    82
import sys
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    83
import wx
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    84
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    85
# Global variables
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    86
# ----------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    87
#
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    88
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    89
__author__ = "Pierre Rouleau"
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    90
__version__= "$Revision: 1.5 $"
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    91
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    92
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    93
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    94
def getlanguageDict():
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    95
    languageDict = {}
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    96
    
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    97
    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    98
        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
    99
        if i:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   100
            languageDict[i.CanonicalName] = i.Description
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   101
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   102
    return languageDict
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   103
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   104
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   105
# m a k e P O ( )         -- Build the Portable Object file for the application --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   106
# ^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   107
#
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   108
def makePO(applicationDirectoryPath,  applicationDomain=None, verbose=0) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   109
    """Build the Portable Object Template file for the application.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   110
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   111
    makePO builds the .pot file for the application stored inside 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   112
    a specified directory by running xgettext for all application source 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   113
    files.  It finds the name of all files by looking for a file called 'app.fil'. 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   114
    If this file does not exists, makePo raises an IOError exception.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   115
    By default the application domain (the application
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   116
    name) is the same as the directory name but it can be overridden by the
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   117
    'applicationDomain' argument.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   118
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   119
    makePO always creates a new file called messages.pot.  If it finds files 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   120
    of the form app_xx.po where 'app' is the application name and 'xx' is one 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   121
    of the ISO 639 two-letter language codes, makePO resynchronizes those 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   122
    files with the latest extracted strings (now contained in messages.pot). 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   123
    This process updates all line location number in the language-specific
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   124
    .po files and may also create new entries for translation (or comment out 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   125
    some).  The .po file is not changed, instead a new file is created with 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   126
    the .new extension appended to the name of the .po file.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   127
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   128
    By default the function does not display what it is doing.  Set the 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   129
    verbose argument to 1 to force it to print its commands.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   130
    """
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   131
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   132
    if applicationDomain is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   133
        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   134
    else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   135
        applicationName = applicationDomain
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   136
    currentDir = os.getcwd()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   137
    os.chdir(applicationDirectoryPath)                    
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   138
    if not os.path.exists('app.fil'):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   139
        raise IOError(2,'No module file: app.fil')
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   140
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   141
    # Steps:                                  
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   142
    #  Use xgettext to parse all application modules
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   143
    #  The following switches are used:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   144
    #  
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   145
    #   -s                          : sort output by string content (easier to use when we need to merge several .po files)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   146
    #   --files-from=app.fil        : The list of files is taken from the file: app.fil
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   147
    #   --output=                   : specifies the name of the output file (using a .pot extension)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   148
    cmd = 'xgettext -s --no-wrap --language=Python --files-from=app.fil --output=messages.pot'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   149
    if verbose: print cmd
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   150
    os.system(cmd)                                                
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   151
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   152
    languageDict = getlanguageDict()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   153
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   154
    for langCode in languageDict.keys():
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   155
        if langCode == 'en':
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   156
            pass
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   157
        else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   158
            langPOfileName = "%s_%s.po" % (applicationName , langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   159
            if os.path.exists(langPOfileName):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   160
                cmd = 'msgmerge -s --no-wrap "%s" messages.pot > "%s.new"' % (langPOfileName, langPOfileName)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   161
                if verbose: print cmd
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   162
                os.system(cmd)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   163
    os.chdir(currentDir)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   164
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   165
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   166
# c a t P O ( )         -- Concatenate one or several PO files with the application domain files. --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   167
# ^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   168
#
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   169
def catPO(applicationDirectoryPath, listOf_extraPo, applicationDomain=None, targetDir=None, verbose=0) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   170
    """Concatenate one or several PO files with the application domain files.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   171
    """
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   172
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   173
    if applicationDomain is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   174
        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   175
    else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   176
        applicationName = applicationDomain
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   177
    currentDir = os.getcwd()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   178
    os.chdir(applicationDirectoryPath)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   179
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   180
    languageDict = getlanguageDict()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   181
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   182
    for langCode in languageDict.keys():
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   183
        if langCode == 'en':
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   184
            pass
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   185
        else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   186
            langPOfileName = "%s_%s.po" % (applicationName , langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   187
            if os.path.exists(langPOfileName):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   188
                fileList = ''
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   189
                for fileName in listOf_extraPo:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   190
                    fileList += ("%s_%s.po " % (fileName,langCode))
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   191
                cmd = "msgcat -s --no-wrap %s %s > %s.cat" % (langPOfileName, fileList, langPOfileName)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   192
                if verbose: print cmd
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   193
                os.system(cmd)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   194
                if targetDir is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   195
                    pass
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   196
                else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   197
                    mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir,langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   198
                    cmd = "msgfmt --output-file=%s/%s.mo %s_%s.po.cat" % (mo_targetDir,applicationName,applicationName,langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   199
                    if verbose: print cmd
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   200
                    os.system(cmd)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   201
    os.chdir(currentDir)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   202
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   203
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   204
# m a k e M O ( )         -- Compile the Portable Object files into the Machine Object stored in the right location. --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   205
# ^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   206
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   207
def makeMO(applicationDirectoryPath,targetDir='./locale',applicationDomain=None, verbose=0, forceEnglish=0) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   208
    """Compile the Portable Object files into the Machine Object stored in the right location.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   209
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   210
    makeMO converts all translated language-specific PO files located inside 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   211
    the  application directory into the binary .MO files stored inside the 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   212
    LC_MESSAGES sub-directory for the found locale files.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   213
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   214
    makeMO searches for all files that have a name of the form 'app_xx.po' 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   215
    inside the application directory specified by the first argument.  The 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   216
    'app' is the application domain name (that can be specified by the 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   217
    applicationDomain argument or is taken from the directory name). The 'xx' 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   218
    corresponds to one of the ISO 639 two-letter language codes.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   219
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   220
    makeMo stores the resulting files inside a sub-directory of `targetDir`
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   221
    called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   222
    code.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   223
    """
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   224
    if targetDir is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   225
        targetDir = './locale'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   226
    if verbose:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   227
        print "Target directory for .mo files is: %s" % targetDir
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   228
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   229
    if applicationDomain is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   230
        applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   231
    else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   232
        applicationName = applicationDomain
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   233
    currentDir = os.getcwd()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   234
    os.chdir(applicationDirectoryPath)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   235
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   236
    languageDict = getlanguageDict()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   237
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   238
    for langCode in languageDict.keys():
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   239
        if (langCode == 'en') and (forceEnglish==0):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   240
            pass
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   241
        else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   242
            langPOfileName = "%s_%s.po" % (applicationName , langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   243
            if os.path.exists(langPOfileName):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   244
                mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir,langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   245
                if not os.path.exists(mo_targetDir):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   246
                    mkdir(mo_targetDir)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   247
                cmd = 'msgfmt --output-file="%s/%s.mo" "%s_%s.po"' % (mo_targetDir,applicationName,applicationName,langCode)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   248
                if verbose: print cmd
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   249
                os.system(cmd)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   250
    os.chdir(currentDir)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   251
   
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   252
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   253
# p r i n t U s a g e         -- Displays how to use this script from the command line --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   254
# ^^^^^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   255
#
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   256
def printUsage(errorMsg=None) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   257
    """Displays how to use this script from the command line."""
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   258
    print """
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   259
    ##################################################################################
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   260
    #   mki18n :   Make internationalization files.                                  #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   261
    #              Uses the GNU gettext system to create PO (Portable Object) files  #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   262
    #              from source code, coimpile PO into MO (Machine Object) files.     #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   263
    #              Supports C,C++,Python source files.                               #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   264
    #                                                                                #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   265
    #   Usage: mki18n {OPTION} [appDirPath]                                          #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   266
    #                                                                                #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   267
    #   Options:                                                                     #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   268
    #     -e               : When -m is used, forces English .mo file creation       #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   269
    #     -h               : prints this help                                        #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   270
    #     -m               : make MO from existing PO files                          #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   271
    #     -p               : make PO, update PO files: Creates a new messages.pot    #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   272
    #                        file. Creates a dom_xx.po.new for every existing        #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   273
    #                        language specific .po file. ('xx' stands for the ISO639 #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   274
    #                        two-letter language code and 'dom' stands for the       #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   275
    #                        application domain name).  mki18n requires that you     #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   276
    #                        write a 'app.fil' file  which contains the list of all  #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   277
    #                        source code to parse.                                   #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   278
    #     -v               : verbose (prints comments while running)                 #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   279
    #     --domain=appName : specifies the application domain name.  By default      #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   280
    #                        the directory name is used.                             #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   281
    #     --moTarget=dir : specifies the directory where .mo files are stored.       #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   282
    #                      If not specified, the target is './locale'                #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   283
    #                                                                                #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   284
    #   You must specify one of the -p or -m option to perform the work.  You can    #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   285
    #   specify the path of the target application.  If you leave it out mki18n      #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   286
    #   will use the current directory as the application main directory.            #        
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   287
    #                                                                                #
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   288
    ##################################################################################"""
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   289
    if errorMsg:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   290
        print "\n   ERROR: %s" % errorMsg
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   291
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   292
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   293
# f i l e B a s e O f ( )         -- Return base name of filename --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   294
# ^^^^^^^^^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   295
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   296
def fileBaseOf(filename,withPath=0) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   297
   """fileBaseOf(filename,withPath) ---> string
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   298
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   299
   Return base name of filename.  The returned string never includes the extension.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   300
   Use os.path.basename() to return the basename with the extension.  The 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   301
   second argument is optional.  If specified and if set to 'true' (non zero) 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   302
   the string returned contains the full path of the file name.  Otherwise the 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   303
   path is excluded.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   304
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   305
   [Example]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   306
   >>> fn = 'd:/dev/telepath/tvapp/code/test.html'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   307
   >>> fileBaseOf(fn)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   308
   'test'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   309
   >>> fileBaseOf(fn)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   310
   'test'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   311
   >>> fileBaseOf(fn,1)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   312
   'd:/dev/telepath/tvapp/code/test'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   313
   >>> fileBaseOf(fn,0)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   314
   'test'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   315
   >>> fn = 'abcdef'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   316
   >>> fileBaseOf(fn)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   317
   'abcdef'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   318
   >>> fileBaseOf(fn,1)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   319
   'abcdef'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   320
   >>> fn = "abcdef."
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   321
   >>> fileBaseOf(fn)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   322
   'abcdef'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   323
   >>> fileBaseOf(fn,1)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   324
   'abcdef'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   325
   """            
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   326
   pos = filename.rfind('.')             
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   327
   if pos > 0:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   328
      filename = filename[:pos]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   329
   if withPath:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   330
      return filename
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   331
   else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   332
      return os.path.basename(filename)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   333
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   334
# m k d i r ( )         -- Create a directory (and possibly the entire tree) --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   335
# ^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   336
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   337
def mkdir(directory) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   338
   """Create a directory (and possibly the entire tree).
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   339
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   340
   The os.mkdir() will fail to create a directory if one of the
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   341
   directory in the specified path does not exist.  mkdir()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   342
   solves this problem.  It creates every intermediate directory
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   343
   required to create the final path. Under Unix, the function 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   344
   only supports forward slash separator, but under Windows and MacOS
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   345
   the function supports the forward slash and the OS separator (backslash
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   346
   under windows).
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   347
   """ 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   348
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   349
   # translate the path separators
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   350
   directory = unixpath(directory)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   351
   # build a list of all directory elements
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   352
   aList = filter(lambda x: len(x)>0, directory.split('/'))
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   353
   theLen = len(aList)                     
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   354
   # if the first element is a Windows-style disk drive
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   355
   # concatenate it with the first directory
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   356
   if aList[0].endswith(':'):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   357
      if theLen > 1:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   358
         aList[1] = aList[0] + '/' + aList[1]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   359
         del aList[0]      
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   360
         theLen -= 1         
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   361
   # if the original directory starts at root,
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   362
   # make sure the first element of the list 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   363
   # starts at root too
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   364
   if directory[0] == '/':     
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   365
      aList[0] = '/' + aList[0]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   366
   # Now iterate through the list, check if the 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   367
   # directory exists and if not create it
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   368
   theDir = ''
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   369
   for i in range(theLen):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   370
      theDir += aList[i]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   371
      if not os.path.exists(theDir):
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   372
         os.mkdir(theDir)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   373
      theDir += '/'   
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   374
      
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   375
# -----------------------------------------------------------------------------
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   376
# u n i x p a t h ( )         -- Return a path name that contains Unix separator. --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   377
# ^^^^^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   378
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   379
def unixpath(thePath) :
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   380
   r"""Return a path name that contains Unix separator.
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   381
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   382
   [Example]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   383
   >>> unixpath(r"d:\test")
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   384
   'd:/test'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   385
   >>> unixpath("d:/test/file.txt")
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   386
   'd:/test/file.txt'
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   387
   >>> 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   388
   """
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   389
   thePath = os.path.normpath(thePath)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   390
   if os.sep == '/':
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   391
      return thePath
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   392
   else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   393
      return thePath.replace(os.sep,'/')
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   394
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   395
# ----------------------------------------------------------------------------- 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   396
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   397
# S c r i p t   e x e c u t i o n               -- Runs when invoked from the command line --
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   398
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   399
# 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   400
if __name__ == "__main__":
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   401
    import getopt     # command line parsing
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   402
    argc = len(sys.argv)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   403
    if argc == 1:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   404
        printUsage('Missing argument: specify at least one of -m or -p (or both).')
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   405
        sys.exit(1)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   406
    # If there is some arguments, parse the command line
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   407
    validOptions     = "ehmpv"
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   408
    validLongOptions = ['domain=', 'moTarget=']             
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   409
    option = {}
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   410
    option['forceEnglish'] = 0
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   411
    option['mo'] = 0
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   412
    option['po'] = 0        
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   413
    option['verbose'] = 0
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   414
    option['domain'] = None
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   415
    option['moTarget'] = None
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   416
    try:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   417
        optionList,pargs = getopt.getopt(sys.argv[1:],validOptions,validLongOptions)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   418
    except getopt.GetoptError, e:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   419
        printUsage(e[0])
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   420
        sys.exit(1)       
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   421
    for (opt,val) in optionList:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   422
        if  (opt == '-h'):    
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   423
            printUsage()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   424
            sys.exit(0) 
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   425
        elif (opt == '-e'):         option['forceEnglish'] = 1
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   426
        elif (opt == '-m'):         option['mo'] = 1
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   427
        elif (opt == '-p'):         option['po'] = 1
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   428
        elif (opt == '-v'):         option['verbose'] = 1
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   429
        elif (opt == '--domain'):   option['domain'] = val
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   430
        elif (opt == '--moTarget'): option['moTarget'] = val
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   431
    if len(pargs) == 0:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   432
        appDirPath = os.getcwd()
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   433
        if option['verbose']:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   434
            print "No project directory given. Using current one:  %s" % appDirPath
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   435
    elif len(pargs) == 1:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   436
        appDirPath = pargs[0]
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   437
    else:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   438
        printUsage('Too many arguments (%u).  Use double quotes if you have space in directory name' % len(pargs))
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   439
        sys.exit(1)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   440
    if option['domain'] is None:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   441
        # If no domain specified, use the name of the target directory
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   442
        option['domain'] = fileBaseOf(appDirPath)
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   443
    if option['verbose']:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   444
        print "Application domain used is: '%s'" % option['domain']
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   445
    if option['po']:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   446
        try:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   447
            makePO(appDirPath,option['domain'],option['verbose'])
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   448
        except IOError, e:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   449
            printUsage(e[1] + '\n   You must write a file app.fil that contains the list of all files to parse.')
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   450
    if option['mo']:
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   451
        makeMO(appDirPath,option['moTarget'],option['domain'],option['verbose'],option['forceEnglish'])
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   452
    sys.exit(1)            
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   453
            
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   454
2ae92a99ac10 Adding support for internationalization
laurent
parents:
diff changeset
   455
# -----------------------------------------------------------------------------