laurent@815: #!/usr/bin/env python
laurent@815: # -*- coding: utf-8 -*-
laurent@815: 
andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
andrej@1511: #
andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
andrej@1511: #
andrej@1511: # See COPYING file for copyrights details.
andrej@1511: #
andrej@1511: # This program is free software; you can redistribute it and/or
andrej@1511: # modify it under the terms of the GNU General Public License
andrej@1511: # as published by the Free Software Foundation; either version 2
andrej@1511: # of the License, or (at your option) any later version.
andrej@1511: #
andrej@1511: # This program is distributed in the hope that it will be useful,
andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1511: # GNU General Public License for more details.
andrej@1511: #
andrej@1511: # You should have received a copy of the GNU General Public License
andrej@1511: # along with this program; if not, write to the Free Software
andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
andrej@1511: 
andrej@1881: 
andrej@1881: from __future__ import absolute_import
andrej@1730: import os
andrej@2431: from six.moves import builtins
laurent@815: import wx
laurent@815: 
andrej@1847: 
andrej@1813: locale = None
laurent@815: 
andrej@1736: 
andrej@2431: builtins.__dict__['_'] = wx.GetTranslation
andrej@1806: 
andrej@1806: 
laurent@815: def GetDomain(path):
laurent@815:     for name in os.listdir(path):
laurent@815:         filepath = os.path.join(path, name)
laurent@815:         basename, fileext = os.path.splitext(name)
laurent@815:         if os.path.isdir(filepath):
laurent@815:             result = GetDomain(filepath)
laurent@815:             if result is not None:
laurent@815:                 return result
laurent@815:         elif fileext == ".mo":
laurent@815:             return basename
laurent@815:     return None
laurent@815: 
andrej@1736: 
laurent@815: def AddCatalog(locale_dir):
laurent@815:     if os.path.exists(locale_dir) and os.path.isdir(locale_dir):
laurent@815:         domain = GetDomain(locale_dir)
laurent@815:         if domain is not None:
andrej@1813:             global locale
andrej@1813:             if locale is None:
andrej@1813:                 # Define locale for wx
andrej@2349:                 wx.LogGui.EnableLogging(False)
andrej@1813:                 locale = wx.Locale(wx.LANGUAGE_DEFAULT)
andrej@2349:                 wx.LogGui.EnableLogging(True)
andrej@1813: 
laurent@815:             locale.AddCatalogLookupPathPrefix(locale_dir)
laurent@815:             locale.AddCatalog(domain)
andrej@1762: 
andrej@1762: 
andrej@1762: def NoTranslate(x):
andrej@1838:     return x