diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 84a770b..c6fb280 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -25,7 +25,7 @@ jobs: - name: msgfmt uses: whtsky/msgfmt-action@20190305 env: - WORKDIR: "locales" + WORKDIR: "pyLSV2/locales" - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} diff --git a/MANIFEST.in b/MANIFEST.in index 0a2c95b..c767196 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include *.md recursive-include scripts *.py -recursive-include locales *.mo \ No newline at end of file +recursive-include pyLSV2 *.mo *.po \ No newline at end of file diff --git a/pyLSV2/__init__.py b/pyLSV2/__init__.py index 4b39110..9397fdd 100644 --- a/pyLSV2/__init__.py +++ b/pyLSV2/__init__.py @@ -3,4 +3,4 @@ """A pure Python3 implementation of the LSV2 protocol""" from .client import LSV2 -__version__ = '0.6.0' +__version__ = '0.6.1' diff --git a/pyLSV2/client.py b/pyLSV2/client.py index b1e3c6e..3a2c3b5 100644 --- a/pyLSV2/client.py +++ b/pyLSV2/client.py @@ -11,6 +11,7 @@ Everything related to PLC or unknown/untested System functions was left out as these function might compromise the control. """ +import os import struct import logging import datetime @@ -655,8 +656,9 @@ def get_program_status_text(code, language='en'): :returns: readable text for execution state :rtype: str """ + locale_path = os.path.dirname(__file__) + '/locales' translate = gettext.translation( - 'message_text', localedir='./locales', languages=[language], fallback=True) + 'message_text', localedir=locale_path, languages=[language], fallback=True) return {LSV2.PGM_STATE_STARTED: translate.gettext('PGM_STATE_STARTED'), LSV2.PGM_STATE_STOPPED: translate.gettext('PGM_STATE_STOPPED'), LSV2.PGM_STATE_FINISHED: translate.gettext('PGM_STATE_FINISHED'), @@ -727,8 +729,9 @@ def get_execution_status_text(code, language='en'): :returns: readable text for execution state :rtype: str """ + locale_path = os.path.dirname(__file__) + '/locales' translate = gettext.translation( - 'message_text', localedir='./locales', languages=[language], fallback=True) + 'message_text', localedir=locale_path, languages=[language], fallback=True) return {LSV2.EXEC_STATE_MANUAL: translate.gettext('EXEC_STATE_MANUAL'), LSV2.EXEC_STATE_MDI: translate.gettext('EXEC_STATE_MDI'), LSV2.EXEC_STATE_PASS_REFERENCES: translate.gettext('EXEC_STATE_PASS_REFERENCES'), diff --git a/locales/de/LC_MESSAGES/error_text.po b/pyLSV2/locales/de/LC_MESSAGES/error_text.po similarity index 100% rename from locales/de/LC_MESSAGES/error_text.po rename to pyLSV2/locales/de/LC_MESSAGES/error_text.po diff --git a/locales/de/LC_MESSAGES/message_text.po b/pyLSV2/locales/de/LC_MESSAGES/message_text.po similarity index 100% rename from locales/de/LC_MESSAGES/message_text.po rename to pyLSV2/locales/de/LC_MESSAGES/message_text.po diff --git a/locales/en/LC_MESSAGES/error_text.po b/pyLSV2/locales/en/LC_MESSAGES/error_text.po similarity index 100% rename from locales/en/LC_MESSAGES/error_text.po rename to pyLSV2/locales/en/LC_MESSAGES/error_text.po diff --git a/locales/en/LC_MESSAGES/message_text.po b/pyLSV2/locales/en/LC_MESSAGES/message_text.po similarity index 100% rename from locales/en/LC_MESSAGES/message_text.po rename to pyLSV2/locales/en/LC_MESSAGES/message_text.po diff --git a/pyLSV2/translate_error.py b/pyLSV2/translate_error.py index 9a8a867..b58bc88 100644 --- a/pyLSV2/translate_error.py +++ b/pyLSV2/translate_error.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- """error code definitions and decoding""" import gettext +import os # Error map LSV2_ERROR_T_ER_BAD_FORMAT = 20 @@ -83,18 +84,19 @@ LSV2_ERROR_T_USER_ERROR = 255 -def get_error_text(error_type, error_code, lang='en'): +def get_error_text(error_type, error_code, language='en'): """Parse error type and error code and return the error message. :param int error_type: type of error code. :param int error_code: code of error message. - :param str lang: language code for message. + :param str language: language code for message. :raise: NotImplementedError if error type is != 1 :return: error message in selected language :rtype: str """ + locale_path = os.path.dirname(__file__) + '/locales' translate = gettext.translation( - 'error_text', localedir='./locales', languages=[lang], fallback=True) + 'error_text', localedir=locale_path, languages=[language], fallback=True) _ = translate.gettext if error_type != 1: