- made the translations work when the app is frozen with CX_freeze

- some formatting changes for the application strings
This commit is contained in:
Marius Stanciu 2019-03-18 03:30:47 +02:00
parent dd2f06c598
commit 3daed4cbfb
9 changed files with 734 additions and 661 deletions

View File

@ -191,12 +191,11 @@ class App(QtCore.QObject):
App.log.debug("Win32!") App.log.debug("Win32!")
else: else:
App.log.debug("Win64!") App.log.debug("Win64!")
self.data_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0) + \
'\FlatCAM' self.data_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0) + '\FlatCAM'
self.os = 'windows' self.os = 'windows'
else: # Linux/Unix/MacOS else: # Linux/Unix/MacOS
self.data_path = os.path.expanduser('~') + \ self.data_path = os.path.expanduser('~') + '/.FlatCAM'
'/.FlatCAM'
self.os = 'unix' self.os = 'unix'
############################### ###############################
@ -2716,27 +2715,32 @@ class App(QtCore.QObject):
layout2.addWidget(logo, stretch=0) layout2.addWidget(logo, stretch=0)
title = QtWidgets.QLabel( title = QtWidgets.QLabel(
"<font size=8><B>FlatCAM</B></font><BR>" _(
"Version %s %s (%s) - %s <BR>" "<font size=8><B>FlatCAM</B></font><BR>"
"<BR>" "Version {version} {beta} ({date}) - {arch} <BR>"
"2D Computer-Aided Printed Circuit Board<BR>" "<BR>"
"Manufacturing.<BR>" "2D Computer-Aided Printed Circuit Board<BR>"
"<BR>" "Manufacturing.<BR>"
"(c) 2014-2019 <B>Juan Pablo Caram</B><BR>" "<BR>"
"<BR>" "(c) 2014-2019 <B>Juan Pablo Caram</B><BR>"
"<B> Main Contributors:</B><BR>" "<BR>"
"Denis Hayrullin<BR>" "<B> Main Contributors:</B><BR>"
"Kamil Sopko<BR>" "Denis Hayrullin<BR>"
"Marius Stanciu<BR>" "Kamil Sopko<BR>"
"Matthieu Berthomé<BR>" "Marius Stanciu<BR>"
"and many others found " "Matthieu Berthomé<BR>"
"<a href = \"https://bitbucket.org/jpcgt/flatcam/pull-requests/?state=MERGED\">here.</a><BR>" "and many others found "
"<BR>" "<a href = \"https://bitbucket.org/jpcgt/flatcam/pull-requests/?state=MERGED\">here.</a><BR>"
"Development is done " "<BR>"
"<a href = \"https://bitbucket.org/jpcgt/flatcam/src/Beta/\">here.</a><BR>" "Development is done "
"DOWNLOAD area " "<a href = \"https://bitbucket.org/jpcgt/flatcam/src/Beta/\">here.</a><BR>"
"<a href = \"https://bitbucket.org/jpcgt/flatcam/downloads/\">here.</a><BR>" "DOWNLOAD area "
"" % (version, ('BETA' if beta else ''), version_date, platform.architecture()[0]) "<a href = \"https://bitbucket.org/jpcgt/flatcam/downloads/\">here.</a><BR>"
""
).format(version=version,
beta=('BETA' if beta else ''),
date=version_date,
arch=platform.architecture()[0])
) )
title.setOpenExternalLinks(True) title.setOpenExternalLinks(True)

View File

@ -8,6 +8,7 @@
import os import os
import sys import sys
from pathlib import Path
from PyQt5 import QtWidgets, QtGui from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import QSettings from PyQt5.QtCore import QSettings
@ -33,9 +34,18 @@ languages_path_search = ''
def load_languages(): def load_languages():
available_translations = []
languages_path_search = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale') languages_path_search = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale')
available_translations = next(os.walk(languages_path_search))[1] try:
available_translations = next(os.walk(languages_path_search))[1]
except StopIteration:
if not available_translations:
languages_path_search = os.path.join(Path(__file__).parents[1], 'locale')
try:
available_translations = next(os.walk(languages_path_search))[1]
except StopIteration:
pass
for lang in available_translations: for lang in available_translations:
try: try:
@ -50,6 +60,10 @@ def languages_dir():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale') return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'locale')
def languages_dir_cx_freeze():
return os.path.join(Path(__file__).parents[1], 'locale')
def on_language_apply_click(app, restart=False): def on_language_apply_click(app, restart=False):
""" """
Using instructions from here: Using instructions from here:
@ -88,6 +102,7 @@ def on_language_apply_click(app, restart=False):
restart_program(app=app) restart_program(app=app)
def apply_language(domain, lang=None): def apply_language(domain, lang=None):
lang_code = '' lang_code = ''
@ -112,7 +127,14 @@ def apply_language(domain, lang=None):
current_lang = gettext.translation(str(domain), localedir=languages_dir(), languages=[lang_code]) current_lang = gettext.translation(str(domain), localedir=languages_dir(), languages=[lang_code])
current_lang.install() current_lang.install()
except Exception as e: except Exception as e:
log.debug("FlatCAMTranslation.apply_language() --> %s" % str(e)) log.debug("FlatCAMTranslation.apply_language() --> %s. Perhaps is Cx_freeze-ed?" % str(e))
try:
current_lang = gettext.translation(str(domain),
localedir=languages_dir_cx_freeze(),
languages=[lang_code])
current_lang.install()
except Exception as e:
log.debug("FlatCAMTranslation.apply_language() --> %s" % str(e))
return name return name

View File

@ -16,7 +16,8 @@ CAD program, and create G-Code for Isolation routing.
- changed some of the app strings formatting to work better with Poedit translation software - changed some of the app strings formatting to work better with Poedit translation software
- fixed bug in Drillcncjob TclCommand - fixed bug in Drillcncjob TclCommand
- finished translation in Romanian - finished translation in Romanian
- made the translations work when the app is frozen with CX_freeze
- some formatting changes for the application strings
16.03.2019 16.03.2019

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -52,8 +52,9 @@ if platform.architecture()[0] == '64bit':
include_files.append((os.path.join(site_dir, "google/protobuf"), "google/protobuf")) include_files.append((os.path.join(site_dir, "google/protobuf"), "google/protobuf"))
include_files.append((os.path.join(site_dir, "ortools"), "ortools")) include_files.append((os.path.join(site_dir, "ortools"), "ortools"))
include_files.append(("share", "lib/share")) include_files.append(("locale", "lib/locale"))
include_files.append(("postprocessors", "lib/postprocessors")) include_files.append(("postprocessors", "lib/postprocessors"))
include_files.append(("share", "lib/share"))
include_files.append(("README.md", "README.md")) include_files.append(("README.md", "README.md"))
include_files.append(("LICENSE", "LICENSE")) include_files.append(("LICENSE", "LICENSE"))