import json
from server_utils.utils import SETTINGS_FOLDER



class TranslationManager:
    def __init__(self, logging, static_folder):
        self.language_code = self.get_current_language_code()
        self.TRANSLATIONS_FOLDER = "{0}/translations/".format(static_folder)
        self.logging = logging
        logging.info("Translation Manager created with this language code {0}".format(self.language_code))

    def get_sentence_by_code(self, status_code):
        try:
            filename = "{0}{1}.json".format(self.TRANSLATIONS_FOLDER, self.language_code)
            translated_sentence = "error"
            status = "error"
            with open(filename, encoding='utf8') as json_file:
                data = json.load(json_file)
                translated_sentence = str(data['sentences'][str(status_code)]["response"])
                status = str(data['sentences'][str(status_code)]["status"])
            return translated_sentence, status
        except KeyError as e:
            self.logging.info("Error getting translation : " + str(e))
            return "error", "error"

    def get_response_text(self, status_code):
        print("Sending response {}".format(status_code))
        return self.get_sentence_by_code(status_code)

    def get_current_language_code(self):
        option_file = SETTINGS_FOLDER + "options.json"
        language_code = "en_US"
        try:
            with open(option_file) as option_file:
                data = json.load(option_file)
                language_code = data['language_code']
            return language_code
        except FileNotFoundError as e:
            return language_code

e4ed0cb82680e6df40995404b464c60b7378c3dc
<mask token>


class TranslationManager:
    <mask token>
    <mask token>

    def get_response_text(self, status_code):
        print('Sending response {}'.format(status_code))
        return self.get_sentence_by_code(status_code)
    <mask token>

<mask token>


class TranslationManager:

    def __init__(self, logging, static_folder):
        self.language_code = self.get_current_language_code()
        self.TRANSLATIONS_FOLDER = '{0}/translations/'.format(static_folder)
        self.logging = logging
        logging.info('Translation Manager created with this language code {0}'
            .format(self.language_code))
    <mask token>

    def get_response_text(self, status_code):
        print('Sending response {}'.format(status_code))
        return self.get_sentence_by_code(status_code)
    <mask token>

<mask token>


class TranslationManager:

    def __init__(self, logging, static_folder):
        self.language_code = self.get_current_language_code()
        self.TRANSLATIONS_FOLDER = '{0}/translations/'.format(static_folder)
        self.logging = logging
        logging.info('Translation Manager created with this language code {0}'
            .format(self.language_code))

    def get_sentence_by_code(self, status_code):
        try:
            filename = '{0}{1}.json'.format(self.TRANSLATIONS_FOLDER, self.
                language_code)
            translated_sentence = 'error'
            status = 'error'
            with open(filename, encoding='utf8') as json_file:
                data = json.load(json_file)
                translated_sentence = str(data['sentences'][str(status_code
                    )]['response'])
                status = str(data['sentences'][str(status_code)]['status'])
            return translated_sentence, status
        except KeyError as e:
            self.logging.info('Error getting translation : ' + str(e))
            return 'error', 'error'

    def get_response_text(self, status_code):
        print('Sending response {}'.format(status_code))
        return self.get_sentence_by_code(status_code)

    def get_current_language_code(self):
        option_file = SETTINGS_FOLDER + 'options.json'
        language_code = 'en_US'
        try:
            with open(option_file) as option_file:
                data = json.load(option_file)
                language_code = data['language_code']
            return language_code
        except FileNotFoundError as e:
            return language_code

import json
from server_utils.utils import SETTINGS_FOLDER


class TranslationManager:

    def __init__(self, logging, static_folder):
        self.language_code = self.get_current_language_code()
        self.TRANSLATIONS_FOLDER = '{0}/translations/'.format(static_folder)
        self.logging = logging
        logging.info('Translation Manager created with this language code {0}'
            .format(self.language_code))

    def get_sentence_by_code(self, status_code):
        try:
            filename = '{0}{1}.json'.format(self.TRANSLATIONS_FOLDER, self.
                language_code)
            translated_sentence = 'error'
            status = 'error'
            with open(filename, encoding='utf8') as json_file:
                data = json.load(json_file)
                translated_sentence = str(data['sentences'][str(status_code
                    )]['response'])
                status = str(data['sentences'][str(status_code)]['status'])
            return translated_sentence, status
        except KeyError as e:
            self.logging.info('Error getting translation : ' + str(e))
            return 'error', 'error'

    def get_response_text(self, status_code):
        print('Sending response {}'.format(status_code))
        return self.get_sentence_by_code(status_code)

    def get_current_language_code(self):
        option_file = SETTINGS_FOLDER + 'options.json'
        language_code = 'en_US'
        try:
            with open(option_file) as option_file:
                data = json.load(option_file)
                language_code = data['language_code']
            return language_code
        except FileNotFoundError as e:
            return language_code

import json
from server_utils.utils import SETTINGS_FOLDER



class TranslationManager:
    def __init__(self, logging, static_folder):
        self.language_code = self.get_current_language_code()
        self.TRANSLATIONS_FOLDER = "{0}/translations/".format(static_folder)
        self.logging = logging
        logging.info("Translation Manager created with this language code {0}".format(self.language_code))

    def get_sentence_by_code(self, status_code):
        try:
            filename = "{0}{1}.json".format(self.TRANSLATIONS_FOLDER, self.language_code)
            translated_sentence = "error"
            status = "error"
            with open(filename, encoding='utf8') as json_file:
                data = json.load(json_file)
                translated_sentence = str(data['sentences'][str(status_code)]["response"])
                status = str(data['sentences'][str(status_code)]["status"])
            return translated_sentence, status
        except KeyError as e:
            self.logging.info("Error getting translation : " + str(e))
            return "error", "error"

    def get_response_text(self, status_code):
        print("Sending response {}".format(status_code))
        return self.get_sentence_by_code(status_code)

    def get_current_language_code(self):
        option_file = SETTINGS_FOLDER + "options.json"
        language_code = "en_US"
        try:
            with open(option_file) as option_file:
                data = json.load(option_file)
                language_code = data['language_code']
            return language_code
        except FileNotFoundError as e:
            return language_code
