Skip to content

Commit

Permalink
[FIX] hreflang default
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiaandreu-ithinkupc committed Feb 3, 2025
1 parent 14ad95a commit 941c53b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
" />

<link rel="alternate" hreflang="x-default"
tal:define="portal_url context/@@genweb.utils/portal_url"
tal:define="lang context/@@genweb.utils/get_default_language_url"
tal:attributes="
href string:${portal_url};
href string:${lang};
" />

15 changes: 15 additions & 0 deletions src/genweb6/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from zope.interface import implementer
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
from Products.CMFCore.utils import getToolByName

from genweb6.core import _
from genweb6.core import HAS_PAM
Expand Down Expand Up @@ -432,6 +433,20 @@ def lit_open_in_new_window(self):

def remove_html_tags(self, text):
return remove_html_tags(text)

def get_default_language_url(self):

tm = ITranslationManager(self.context)
catalog = api.portal.get_tool(name='portal_catalog')
results = catalog(TranslationGroup=tm.query_canonical())
registry_tool = getToolByName(self, "portal_registry")
lang = registry_tool['plone.default_language']
for item in results:
if item.Language == lang:
return item.getURL()

return self.context.absolute_url()



@implementer(ICatalogFactory)
Expand Down

0 comments on commit 941c53b

Please sign in to comment.