Skip to content

Commit

Permalink
fix problem with translation not working because of missing mo files
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Jan 27, 2021
1 parent f50ecd7 commit a6e612b
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include *.md
recursive-include scripts *.py
recursive-include locales *.mo
recursive-include pyLSV2 *.mo *.po
2 changes: 1 addition & 1 deletion pyLSV2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""A pure Python3 implementation of the LSV2 protocol"""
from .client import LSV2

__version__ = '0.6.0'
__version__ = '0.6.1'
7 changes: 5 additions & 2 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions pyLSV2/translate_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a6e612b

Please sign in to comment.