Skip to content

Commit

Permalink
Merge pull request #1641 from RogerHaase/39-lang
Browse files Browse the repository at this point in the history
language attributes missing; fixes #39
  • Loading branch information
RogerHaase authored Mar 12, 2024
2 parents 6ce8bcd + 2032b80 commit cbfeb83
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/admin/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Here is the source code segment from snippets.html::

{# Header/Sidebar for topside_cms theme - see docs for tips on customization #}
{% macro cms_header() %}
<header id="moin-header">
<header id="moin-header" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
{% block header %}

{% if logo() %}
Expand Down
3 changes: 0 additions & 3 deletions src/moin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,6 @@ def before_wiki():
flaskg.dicts = app.cfg.dicts()
flaskg.groups = app.cfg.groups()

flaskg.content_lang = app.cfg.language_default
flaskg.current_lang = app.cfg.language_default

if cli_no_request_ctx: # no request.user_agent if this is pytest or cli
flaskg.add_lineno_attr = False
else:
Expand Down
4 changes: 4 additions & 0 deletions src/moin/cli/migration/moin19/import19.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def __init__(self, item, revno, path, target_namespace):
meta[REV_NUMBER] = revno
meta[NAMESPACE] = target_namespace
meta[ITEMTYPE] = ITEMTYPE_DEFAULT
if LANGUAGE not in meta:
meta[LANGUAGE] = app.cfg.language_default
if meta[NAME][0].endswith('Template'):
if TAGS in meta:
meta[TAGS].append(TEMPLATE)
Expand Down Expand Up @@ -644,6 +646,8 @@ def __init__(self, item_name, attach_name, attpath, editlog, acl):
meta[REVID] = make_uuid()
meta[REV_NUMBER] = 1
meta[ITEMTYPE] = ITEMTYPE_DEFAULT
if LANGUAGE not in meta:
meta[LANGUAGE] = app.cfg.language_default
meta[WIKINAME] = app.cfg.sitename # old 1.9 sitename is not available
for attr in (COMMENT, SUMMARY, ):
meta[attr] = ""
Expand Down
5 changes: 3 additions & 2 deletions src/moin/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import re
import os

from babel import parse_locale
from babel import Locale, parse_locale

from moin.i18n import _, L_, N_
from moin import error
Expand Down Expand Up @@ -87,7 +87,8 @@ def __init__(self):
# to give browser language detection a chance.
try:
self.language_default = parse_locale(self.locale_default)[0]
except ValueError:
self.content_dir = Locale(self.language_default).text_direction
except Exception: # noqa
raise error.ConfigurationError("Invalid locale_default value (give something like 'en_US').")

# post process
Expand Down
50 changes: 25 additions & 25 deletions src/moin/converters/_tests/test_include.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/moin/converters/html_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import re

from flask import current_app as app
from flask import g as flaskg
from emeraldtree import ElementTree as ET
from urllib.parse import urlencode
from babel import Locale

from moin import wikiutil
from moin.i18n import _
Expand All @@ -22,6 +24,7 @@
from moin.utils.tree import html, moin_page, xlink, xml
from moin.constants.contenttypes import CONTENTTYPE_NONEXISTENT, CHARSET
from moin.utils.mime import Type, type_moin_document
from moin.constants.keys import LANGUAGE

from . import default_registry, ElementException

Expand Down Expand Up @@ -65,6 +68,13 @@ def mark_item_as_transclusion(elem, href_or_item):
if isinstance(href_or_item, Item):
query = urlencode({'do': 'show'}, encoding=CHARSET)
href = Iri(scheme='wiki', authority='', path='/' + href_or_item.fqname.fullname, query=query)
if hasattr(href_or_item, 'meta') and LANGUAGE in href_or_item.meta:
elem.attrib[html.lang] = href_or_item.meta[LANGUAGE]
elif hasattr(flaskg.user, LANGUAGE):
elem.attrib[html.lang] = flaskg.user.language
else:
elem.attrib[html.lang] = app.cfg.language_default
elem.attrib[html.dir] = Locale(elem.attrib[html.lang]).text_direction
else: # isinstance(href_or_item, Iri)
href = href_or_item
elem.attrib[html.data_href] = href
Expand Down
6 changes: 5 additions & 1 deletion src/moin/items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
HASH_ALGORITHM, ITEMID, REVID, DATAID, CURRENT, PARENTID, NAMESPACE,
UFIELDS_TYPELIST, UFIELDS, TRASH, REV_NUMBER,
ACTION_SAVE, ACTION_REVERT, ACTION_TRASH, ACTION_RENAME, TAGS, TEMPLATE,
LATEST_REVS, EDIT_ROWS, FQNAMES, USERGROUP, WIKIDICT
LATEST_REVS, EDIT_ROWS, FQNAMES, USERGROUP, WIKIDICT, LANGUAGE
)
from moin.constants.chartypes import CHARS_UPPER, CHARS_LOWER
from moin.constants.namespaces import NAMESPACE_ALL, NAMESPACE_USERPROFILES
Expand Down Expand Up @@ -990,6 +990,10 @@ def _save(self, meta, data=None, names=None, action=ACTION_SAVE, contenttype_gue
contenttype_current = None

meta = dict(meta) # we may get a read-only dict-like, copy it
if flaskg.user.language:
meta[LANGUAGE] = flaskg.user.language
else:
meta[LANGUAGE] = app.cfg.language_default

if 'acl' in meta:
# we treat this as nothing specified, so fallback to default
Expand Down
4 changes: 2 additions & 2 deletions src/moin/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div id="moin-main-wrapper">
{{ before_header }}
<header id="moin-header">
<header id="moin-header" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
{% block header %}
{% if search_form %}
{{ header_search(search_form) }}
Expand Down Expand Up @@ -52,7 +52,7 @@
</header>
{{ after_header }}

<div id="moin-page" role="main" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
<div id="moin-page" role="main">
{% block item -%}
{# If you want itemviews in your template, extend from show.html, not from here. #}
<div id="moin-content">
Expand Down
4 changes: 2 additions & 2 deletions src/moin/templates/snippets.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

{% macro footer_meta() %}
{% if rev %}
<p id="moin-pageinfo" lang="{{ theme_supp.ui_lang }}" dir="{{ theme_supp.ui_dir }}">
<p id="moin-pageinfo">
{% if cfg.show_interwiki %}
{{ cfg.interwikiname }}:
{% endif %}
Expand Down Expand Up @@ -109,7 +109,7 @@

{# Header/Sidebar for topside_cms theme - see docs for tips on customization #}
{% macro cms_header() %}
<header id="moin-header">
<header id="moin-header" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
{% block header %}

{% if logo() %}
Expand Down
10 changes: 6 additions & 4 deletions src/moin/themes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from flask import url_for, request
from flask_theme import get_theme, render_theme_template

from babel import Locale

from moin.i18n import _, L_
from moin import wikiutil, user
from moin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT, ASSIGNED_TO, NAME, NAMESPACE
Expand Down Expand Up @@ -84,10 +86,10 @@ def __init__(self, cfg):
self.cfg = cfg
self.user = flaskg.user
self.storage = flaskg.storage
self.ui_lang = 'en' # XXX
self.ui_dir = 'ltr' # XXX
self.content_lang = flaskg.content_lang # XXX
self.content_dir = 'ltr' # XXX
self.ui_lang = cfg.language_default
self.ui_dir = cfg.content_dir
self.user_lang = flaskg.user.language or self.ui_lang
self.user_dir = Locale(self.user_lang).text_direction
if request.url_root[len(request.host_url):-1]:
self.wiki_root = '/' + request.url_root[len(request.host_url):-1]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/moin/themes/basic/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="container-fluid">
<div id="moin-main-wrapper" class="row">

<header class="col-md-2 col-sm-2 col-xs-4 moin-sidebar">
<header class="col-md-2 col-sm-2 col-xs-4 moin-sidebar" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
<div class="moin-logo">
{% if logo %}
<a href="{{ url_for('frontend.show_item', item_name=cfg.item_root) }}">
Expand Down
4 changes: 2 additions & 2 deletions src/moin/themes/topside/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div id="moin-main-wrapper">
{{ snippets.before_header() }}
<header id="moin-header">
<header id="moin-header" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
{%- block header %}
{%- if snippets.logo() %}
<div id="moin-logo">
Expand Down Expand Up @@ -57,7 +57,7 @@
</header>
{{ snippets.after_header() }}

<div id="moin-page" role="main" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
<div id="moin-page" role="main">
{% block item -%}
{# If you want itemviews in your template, extend from show.html, not from here. #}
<div id="moin-content">
Expand Down
2 changes: 1 addition & 1 deletion src/moin/themes/topside_cms/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{ snippets.cms_header() }}
{{ snippets.after_header() }}

<div id="moin-page" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
<div id="moin-page">
{% block item -%}
<div id="moin-content">
<div id="moin-flash"> {# client side javascript may add messages here #}
Expand Down

0 comments on commit cbfeb83

Please sign in to comment.