def test_context_manager(self): locale1 = i18n.Locale('fr', 'FR', domain='domain1') locale2 = i18n.Locale('fr', 'FR', domain='domain2') i18n.set_locale(locale1) self.assertEqual(i18n.get_locale().domain, 'domain1') with locale2: self.assertEqual(i18n.get_locale().domain, 'domain2') with locale2: self.assertEqual(i18n.get_locale().domain, 'domain2') self.assertEqual(i18n.get_locale().domain, 'domain1')
def test_context_manager(): locale1 = i18n.Locale('fr', 'FR', domain='domain1') locale2 = i18n.Locale('fr', 'FR', domain='domain2') i18n.set_locale(locale1) assert i18n.get_locale().domain == 'domain1' with locale2: assert i18n.get_locale().domain == 'domain2' with locale2: assert i18n.get_locale().domain == 'domain2' assert i18n.get_locale().domain == 'domain1'
def create_user(self, username, password, fullname, email, source=u'application', picture=None, create_board=True): from ..authentication.database import forms from ..board.boardsmanager import BoardsManager user = DataUser(username, password, fullname, email, source, picture, language=i18n.get_locale().language) token_gen = forms.TokenGenerator(email, u'invite board') for token in token_gen.get_tokens(): if token_gen.check_token(token.token) and token.board: user.add_board(token.board) token_gen.reset_token(token.token) if create_board: BoardsManager().create_board(u"Welcome Board", user, True) return user
def _save_locale(self, response): language = i18n.get_locale().language response.set_cookie('language', language, max_age=timedelta(days=365)) current_user = get_current_user() if current_user: current_user.locale = language
def _save_locale(self, response): language = i18n.get_locale().language response.set_cookie("language", language, max_age=timedelta(days=365)) current_user = get_current_user() if current_user: current_user.locale = language
def get_locale(self): locale = i18n.Locale(self.data.language) # At this point, the locale object only knows about builtin Nagare translation directories # We need to register Kansha's translation directories too (get them from the current locale) locale.translation_directories.update(i18n.get_locale().translation_directories) return locale
def get_locale(self): locale = i18n.Locale(self.data.language) # At this point, the locale object only knows about builtin Nagare translation directories # We need to register Kansha's translation directories too (get them from the current locale) locale.translation_directories.update( i18n.get_locale().translation_directories) return locale
def test_context_manager(): locale1 = i18n.Locale('fr', 'FR', domain='domain1') locale2 = i18n.Locale('fr', 'FR', domain='domain2') i18n.set_locale(locale1) assert i18n.get_locale().domain == 'domain1', i18n.get_locale().domain with locale2: assert i18n.get_locale().domain == 'domain2', i18n.get_locale().domain with locale2: assert i18n.get_locale().domain == 'domain2', i18n.get_locale().domain assert i18n.get_locale().domain == 'domain1', i18n.get_locale().domain
def create_user(self, username, password, fullname, email, source=u'application', picture=None): from kansha.authentication.database import forms user = DataUser(username, password, fullname, email, source, picture, language=i18n.get_locale().language) token_gen = forms.TokenGenerator(email, u'invite board') for token in token_gen.get_tokens(): if token_gen.check_token(token.token) and token.board: user.add_board(token.board) token_gen.reset_token(token.token) return user
def create_user(self, username, password, fullname, email, source=u'application', picture=None): from kansha.authentication.database import forms user = DataUser(username, password, fullname, email, source, picture, language=i18n.get_locale().language) token_gen = forms.TokenGenerator(email, u'invite board') for token in token_gen.get_tokens(): if token_gen.check_token(token.token) and token.board: token.board.add_member(user) token_gen.reset_token(token.token) return user
def language(self, language): locale_info = (language, None) locale_dir = i18n.get_locale().dirname domain = i18n.get_locale().domain i18n.set_locale( i18n.Locale(*locale_info, domain=domain, dirname=locale_dir))
def language(self, language): locale_info = (language, None) locale_dir = i18n.get_locale().dirname domain = i18n.get_locale().domain i18n.set_locale(i18n.Locale(*locale_info, domain=domain, dirname=locale_dir))
def language(self): return i18n.get_locale().language
def xml_file(self): language = i18n.get_locale().language return resource_stream(os.path.join('data', 'staticcontent', language, self.filename))