Skip to content

Commit

Permalink
[Feature] added locale support for NicknamePokemon (#2539)
Browse files Browse the repository at this point in the history
* added locale support for NicknamePokemon
added pokemon_de.json
beautyfied pokemon.json

* fallback to en instead of throwing runtime error

* remove log

* added locales: fr, ja, pt_br, ru, zh

* minor fix
  • Loading branch information
mhdasding authored and elicwhite committed Aug 13, 2016
1 parent dbf26d5 commit 9b72ee5
Show file tree
Hide file tree
Showing 10 changed files with 5,919 additions and 1 deletion.
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

0 comments on commit 9b72ee5

Please sign in to comment.