Skip to content

Commit 5bc5c0d

Browse files
committed
XWIKI-17700: Information tab doesn't show the right current locale when locale is none
* Pass the language parameter when requesting the document extra tabs * Show a warning when a document with no language set has translations * Don't show the Translate button for pages with no language set if the existing translations are for unsupported locales. * Don't show the create translation links if the default translation has no language set.
1 parent d8536f8 commit 5bc5c0d

File tree

5 files changed

+58
-36
lines changed

5 files changed

+58
-36
lines changed

xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-resources/src/main/resources/flamingo/menus_content.vm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@
5959
## * multilingual is on
6060
## * the user can edit the current document
6161
## * the user is viewing the original document version
62-
## * the document is translatable (either has a default locale specified or it has existing translations)
63-
## * the current UI locale doesn't match the original document locale
62+
## * the document is translatable (either has a default locale specified or it has existing translations for the
63+
## supported locales)
64+
## * the current UI locale doesn't match the original document locale, and there's no existing translation for it
65+
#set ($supportedTranslationLocales = $doc.translationLocales)
66+
#set ($discard = $supportedTranslationLocales.retainAll($xwiki.availableLocales))
6467
#if (
6568
$displayTranslateMenu &&
6669
$xwiki.isMultiLingual() &&
6770
$hasEdit && !$isReadOnly &&
6871
$xcontext.action == 'view' && $tdoc.realLocale == $doc.realLocale &&
69-
("$!doc.realLocale" != '' || !$doc.translationLocales.isEmpty()) &&
70-
$doc.realLocale != $xcontext.locale
72+
("$!doc.realLocale" != '' || !$supportedTranslationLocales.isEmpty()) &&
73+
$doc.realLocale != $xcontext.locale && !$supportedTranslationLocales.contains($xcontext.locale)
7174
)
7275
#displayTranslateMenu()
7376
#end

xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/ApplicationResources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ core.viewers.history.empty="The history of this page is empty."
12131213
core.viewers.information.title=Information about <a href="{1}">{0}</a>
12141214
core.viewers.information.locale=Language
12151215
core.viewers.information.noLocale=None
1216+
core.viewers.information.noLocaleWarning=A page with no language set shouldn't have translations.
12161217
core.viewers.information.originalLocale=Default language
12171218
core.viewers.information.translations=Translations
12181219
core.viewers.information.syntax=Syntax

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/main/resources/templates/display_macros.vm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@
7373
#foreach ($translationLocale in $doc.translationLocales)
7474
#set ($discard = $macro.disabledLocales.add("$translationLocale"))
7575
#end
76+
## Allow selecting no locale if there are no document translations or there is already no locale selected.
77+
#set ($macro.allowEmpty = $doc.translationLocales.isEmpty() || "$!tdoc.defaultLocale" == '')
7678
#set ($macro.parameters = {
7779
'id': 'xwikidoclanguageinput2',
7880
'name': 'defaultLanguage',
7981
'value': $tdoc.defaultLocale,
8082
'mode': $displayMode,
8183
'settings': {
82-
'allowEmpty': $doc.translationLocales.isEmpty(),
84+
'allowEmpty': $macro.allowEmpty,
8385
'supportedLocales': $macro.supportedLocales,
8486
'disabledLocales':$macro.disabledLocales,
8587
'disabledLocalesHint': $services.localization.render('web.templates.documentLocalePicker.existingTranslation')

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/main/resources/templates/informationinline.vm

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
## ---------------------------------------------------------------------------
2020
#template('display_macros.vm')
2121
#initRequiredSkinExtensions()
22+
2223
#macro(docTranslationLink $locale $action $fragment)
2324
#set ($localeName = $locale.getDisplayName($xcontext.locale))
2425
#if ("$!localeName" == '')
@@ -32,6 +33,15 @@
3233
#end
3334
<a href="$translationURL" data-locale="$escapetool.xml($locale)">$escapetool.xml($localeName)</a>
3435
#end
36+
37+
#macro (_maybeShowNoLocaleWarning)
38+
#if ("$!doc.realLocale" == '')
39+
<span title="$escapetool.xml($services.localization.render('core.viewers.information.noLocaleWarning'))">
40+
$services.icon.renderHTML('warning')
41+
</span>
42+
#end
43+
#end
44+
3545
$xwiki.jsfx.use('js/xwiki/viewers/information.js', {'forceSkinAction': true, 'language': ${xcontext.locale}})
3646
$xwiki.ssfx.use('js/xwiki/viewers/information.css', true)
3747
$xwiki.jsfx.use('uicomponents/edit/editableProperty.js', {'forceSkinAction': true, 'language': $xcontext.locale})
@@ -60,6 +70,7 @@ $xwiki.jsfx.use('uicomponents/edit/editableProperty.js', {'forceSkinAction': tru
6070
#set ($discard = $staticUIX.add({'content': "
6171
<dt>
6272
<label>$escapetool.xml($services.localization.render('core.viewers.information.originalLocale'))</label>
73+
#_maybeShowNoLocaleWarning()
6374
</dt>
6475
<dd data-key=""originalLocale"">#docTranslationLink($doc.realLocale 'view')</dd>
6576
",
@@ -71,40 +82,40 @@ $xwiki.jsfx.use('uicomponents/edit/editableProperty.js', {'forceSkinAction': tru
7182
## Translations
7283
##
7384
#set ($existingTranslations = $doc.translationLocales)
74-
## Show the list of translations if multilingual is on and either the original page is translatable (has a
75-
## locale specified) or it has existing translations.
76-
#if ($xwiki.isMultiLingual() && ("$!doc.realLocale" != '' || !$existingTranslations.isEmpty()))
85+
## Show the list of translations if multilingual is on.
86+
#if ($xwiki.isMultiLingual())
7787
#set ($supportedLocales = $xwiki.availableLocales)
7888
## Remove the translations that we already display above.
7989
#set ($discard = $supportedLocales.remove($tdoc.realLocale))
8090
#set ($discard = $supportedLocales.remove($doc.realLocale))
81-
#if (!$supportedLocales.isEmpty())
82-
#set ($output = [])
83-
#foreach ($supportedLocale in $supportedLocales)
84-
#if ($existingTranslations.contains($supportedLocale))
85-
#set ($discard = $output.add($stringtool.trim("#docTranslationLink($supportedLocale 'view')")))
86-
#elseif ($hasEdit)
87-
## Show the link to create the missing translation if the current user can edit the page. Use the
88-
## preferred edit mode (in-place versus stand-alone) depending on the user preferences, in order to
89-
## replicate the behavior of the Translate button.
90-
#set ($action = 'edit')
91-
#set ($fragment = $NULL)
92-
#getDefaultDocumentEditor($defaultEditMode)
93-
#if ($services.edit.document.inPlaceEditingEnabled() && $defaultEditMode == 'wysiwyg')
94-
## Link to the in-place page editor which currently uses the view action.
95-
#set ($action = 'view')
96-
#set ($fragment = 'translate')
97-
#end
98-
#set ($discard = $output.add(
99-
"<span class='wikicreatelink skipCreatePagePopup'>" +
100-
$stringtool.trim("#docTranslationLink($supportedLocale $action $fragment)") +
101-
"</span>"
102-
))
91+
#set ($output = [])
92+
#foreach ($supportedLocale in $supportedLocales)
93+
#if ($existingTranslations.contains($supportedLocale))
94+
#set ($discard = $output.add($stringtool.trim("#docTranslationLink($supportedLocale 'view')")))
95+
#elseif ($hasEdit && "$!doc.realLocale" != '')
96+
## Show the link to create the missing translation if the current user can edit the page and the default
97+
## translation has a locale set (i.e. if the page can be translated). Use the preferred edit mode (in-place versus
98+
## stand-alone) depending on the user preferences, in order to replicate the behavior of the Translate button.
99+
#set ($action = 'edit')
100+
#set ($fragment = $NULL)
101+
#getDefaultDocumentEditor($defaultEditMode)
102+
#if ($services.edit.document.inPlaceEditingEnabled() && $defaultEditMode == 'wysiwyg')
103+
## Link to the in-place page editor which currently uses the view action.
104+
#set ($action = 'view')
105+
#set ($fragment = 'translate')
103106
#end
107+
#set ($discard = $output.add(
108+
"<span class='wikicreatelink skipCreatePagePopup'>" +
109+
$stringtool.trim("#docTranslationLink($supportedLocale $action $fragment)") +
110+
"</span>"
111+
))
104112
#end
113+
#end
114+
#if (!$output.isEmpty())
105115
#set ($discard = $staticUIX.add({'content': "
106116
<dt>
107117
<label>$escapetool.xml($services.localization.render('core.viewers.information.translations'))</label>
118+
#_maybeShowNoLocaleWarning()
108119
</dt>
109120
<dd data-key=""translations"">$stringtool.join($output, ', ')</dd>
110121
",

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/js/xwiki/xwiki.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,22 @@ Object.extend(XWiki, {
210210
}
211211
$("docextrapanes").className="loading";
212212

213-
// Determine if JS minification is disabled in the URL. Needed to pass it to the AJAX call to get the right resources on the reply.
214-
var maybeMinifyRequestParameter = '';
215-
var requestMinify = window.location.search.toQueryParams().minify;
216-
if (requestMinify && requestMinify == 'false') {
217-
maybeMinifyRequestParameter = '&minify=false';
213+
const parameters = {
214+
'xpage': 'xpart',
215+
'vm': extraTemplate,
216+
'language': document.documentElement.dataset.xwikiLocale
217+
};
218+
// Determine if JavaScript minification is disabled from the URL. We need to pass it to the AJAX call in order
219+
// to get the right resources on the response.
220+
if (new URLSearchParams(window.location.search).get('minify') === 'false') {
221+
parameters.minify = 'false';
218222
}
219223

220224
new Ajax.Request(
221-
window.docgeturl + '?xpage=xpart&vm=' + extraTemplate + maybeMinifyRequestParameter,
225+
window.docgeturl,
222226
{
223227
method: 'get',
228+
parameters,
224229
onSuccess: function(response) {
225230
// Do the work that Ajax.Updater is supposed to do, but we can't use it because it strips the <script>s
226231
// from the output and we need to inject the external scripts from the reply (in the DOM's dead), to execute them.

0 commit comments

Comments
 (0)