Skip to content

Commit

Permalink
Make generated behaviors language independent (#67)
Browse files Browse the repository at this point in the history
* Make generated behaviors language independent

* Use taxonomy default language for indexing if current language is not available

* use api for current language
  • Loading branch information
agitator committed Jun 17, 2019
1 parent 1f4931b commit f95ab38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changes
2.0.0 (unreleased)
------------------

- Use taxonomy default language for indexing if current language is not available
[agitator]

- Make generated behaviors language independent
[agitator]

- export selected taxonomies as ZIPed folder with XML files
[petschki]

Expand Down
13 changes: 13 additions & 0 deletions src/collective/taxonomy/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
from zope.component.hooks import getSite
from zope.interface import alsoProvides
from zope.interface import implementer
import pkg_resources

try:
pkg_resources.get_distribution('plone.app.multilingual')
except pkg_resources.DistributionNotFound:
HAS_PAM = False
else:
from plone.app.multilingual.dx.interfaces import ILanguageIndependentField
HAS_PAM = True

logger = logging.getLogger("collective.taxonomy")

Expand Down Expand Up @@ -192,4 +201,8 @@ def generateInterface(self):
)

alsoProvides(schemaclass, IFormFieldProvider)

if HAS_PAM:
alsoProvides(schemaclass[self.field_name], ILanguageIndependentField)

return schemaclass
3 changes: 3 additions & 0 deletions src/collective/taxonomy/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __call__(self):
found.append((identifier, language, path,))

lang = get_language(self.context)
if lang not in utility.inverted_data:
lang = utility.default_language

result = []
for (key, value) in utility.inverted_data[lang].items():
for (found_identifier, found_language, found_path) in found:
Expand Down
4 changes: 1 addition & 3 deletions src/collective/taxonomy/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ def translate(self, msgid, mapping=None, context=None,

if target_language is None or \
target_language not in self.inverted_data:
target_language = str(self.getCurrentLanguage(
getattr(context, 'REQUEST')
))
target_language = str(api.portal.get_current_language())

if msgid not in self.inverted_data[target_language]:
return ''
Expand Down

0 comments on commit f95ab38

Please sign in to comment.