Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] added locale support for NicknamePokemon #2539

Merged
merged 6 commits into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
746 changes: 746 additions & 0 deletions data/locales/de.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions data/locales/fr.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions data/locales/ja.json

Large diffs are not rendered by default.

702 changes: 702 additions & 0 deletions data/locales/pt_br.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions data/locales/ru.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions data/locales/zh_cn.json

Large diffs are not rendered by default.

723 changes: 723 additions & 0 deletions data/locales/zh_hk.json

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions data/locales/zh_tw.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/pokemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -5897,4 +5897,4 @@
"CaptureRate": 0,
"FleeRate": 0.1
}
]
]
17 changes: 17 additions & 0 deletions pokemongo_bot/cell_workers/nickname_pokemon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import json
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.inventory import pokemons, Pokemon, Attack
Expand Down Expand Up @@ -186,6 +188,13 @@ def initialize(self):
self.template = self.config.get(
'nickname_template', DEFAULT_TEMPLATE)

self.translate = None
locale = self.config.get('locale', 'en')
if locale != 'en':
fn = 'data/locales/{}.json'.format(locale)
if os.path.isfile(fn):
self.translate = json.load(open(fn))

def work(self):
"""
Iterate over all user pokemons and nickname if needed
Expand All @@ -194,6 +203,12 @@ def work(self):
if not pokemon.is_favorite or not self.ignore_favorites:
self._nickname_pokemon(pokemon)

def _localize(self, string):
if self.translate and string in self.translate:
return self.translate[string]
else:
return string

def _nickname_pokemon(self, pokemon):
# type: (Pokemon) -> None
"""
Expand Down Expand Up @@ -305,6 +320,8 @@ def _generate_new_nickname(self, pokemon, template):

moveset = pokemon.moveset

pokemon.name = self._localize(pokemon.name)

#
# Generate new nickname
#
Expand Down