Skip to content

Commit

Permalink
Change locale when language changes
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Sep 11, 2017
1 parent 8be9d0a commit a687260
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
34 changes: 33 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Workflow
workflows:
version: 2
test__dockerhub:
jobs:
- test
- trigger_components:
requires:
- test
filters:
branches:
only: master

version: 2
jobs:
build:
test:
docker:
- image: circleci/python:3.6.1
- image: eclipse-mosquitto:latest
Expand Down Expand Up @@ -36,6 +49,10 @@ jobs:
name: run tests
command: |
. venv/bin/activate
locale -a
sudo locale-gen fr_FR.UTF-8
sudo locale-gen en_US.UTF-8
locale -a
python setup.py develop
pycodestyle --max-line-length=100 tuxeatpi_common
pylint --rcfile=.pylintrc -r no tuxeatpi_common
Expand All @@ -48,3 +65,18 @@ jobs:
# Useless for now waiting for update from circleCI UI
- store_test_results:
path: pytest/
trigger_components:
docker:
- image: circleci/python:3.6.1
working_directory: ~/repo
steps:
- run:
name: trigger components
commands: |
curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/brain/tree/master?circle-token=$CIRCLE_TOKEN
curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/hotword-kittai/tree/master?circle-token=$CIRCLE_TOKEN
curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/speech-nuance/tree/master?circle-token=$CIRCLE_TOKEN
curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/nlu-nuance/tree/master?circle-token=$CIRCLE_TOKEN
curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/time/tree/master?circle-token=$CIRCLE_TOKEN
# curl -v -X POST https://circleci.com/api/v1/project/github/TuxEatPi/being/tree/master?circle-token=$CIRCLE_TOKEN
8 changes: 6 additions & 2 deletions tuxeatpi_common/etcd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def _connect(self):
# Save client
self.sync_client = etcd_client
break
except (etcd.EtcdConnectionFailed, urllib3.exceptions.MaxRetryError):
except (etcd.EtcdConnectionFailed,
urllib3.exceptions.MaxRetryError,
etcd.EtcdException):
self.logger.warning("Can not connect to etcd server, retrying in 5 seconds")
time.sleep(5)
# Get sync client sender
Expand All @@ -55,7 +57,9 @@ def _connect(self):
# Save client
self.sync_sender = etcd_sender
break
except (etcd.EtcdConnectionFailed, urllib3.exceptions.MaxRetryError):
except (etcd.EtcdConnectionFailed,
urllib3.exceptions.MaxRetryError,
etcd.EtcdException):
self.logger.warning("Can not connect to etcd server, retrying in 5 seconds")
time.sleep(5)
# Get async etcd client
Expand Down
4 changes: 4 additions & 0 deletions tuxeatpi_common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import json
import locale


class SettingsHandler(object):
Expand Down Expand Up @@ -79,6 +80,9 @@ async def read_global(self, watch=False):
if data.get('language') != self.language:
self.language = data['language']
self.logger.info("Language %s set", self.language)
# Set locale
encoding = locale.getlocale()[1]
locale.setlocale(locale.LC_ALL, (self.language, encoding))
# TODO Implement reload or not ???
self._reload_needed = True
self.logger.info("Reloading")
Expand Down

0 comments on commit a687260

Please sign in to comment.