Santhosh has submitted this change and it was merged.
Change subject: Apply light formatting in page mode
......................................................................
Apply light formatting in page mode
Bug: 45548
Change-Id: I1e131ad18008fa05784c4f67efd798a9c0598484
---
M Translate.php
M resources/js/ext.translate.messagetable.js
A resources/js/ext.translate.parsers.js
3 files changed, 79 insertions(+), 7 deletions(-)
Approvals:
Santhosh: Verified; Looks good to me, approved
diff --git a/Translate.php b/Translate.php
index b939c77..6d96ce3 100644
--- a/Translate.php
+++ b/Translate.php
@@ -203,9 +203,6 @@
require( "$dir/Resources.php" );
-/** @endcond */
-
-
# == Configuration variables ==
# === Basic configuration ===
diff --git a/resources/js/ext.translate.messagetable.js
b/resources/js/ext.translate.messagetable.js
index 0199f79..1435b0d 100644
--- a/resources/js/ext.translate.messagetable.js
+++ b/resources/js/ext.translate.messagetable.js
@@ -260,16 +260,14 @@
lang: sourceLanguage,
dir: sourceLanguageDir
} )
- // FIXME this should be parsed
wiki text
- .text( message.definition ),
+ .html(
mw.translate.formatMessageGently( message.definition, message.key ) ),
$( '<div>' )
.addClass( 'six columns
tux-proofread-translation' )
.attr( {
lang: targetLanguage,
dir: targetLanguageDir
} )
- // FIXME this should be parsed
wiki text
- .text( message.translation ||
'' )
+ .html(
mw.translate.formatMessageGently( message.translation || '', message.key ) )
);
this.$container.append( $message );
diff --git a/resources/js/ext.translate.parsers.js
b/resources/js/ext.translate.parsers.js
new file mode 100644
index 0000000..0cbc277
--- /dev/null
+++ b/resources/js/ext.translate.parsers.js
@@ -0,0 +1,77 @@
+/*
+ * A set of simple tools for partial parsing and formatting of translatable
+ * messages.
+ *
+ * @author Niklas Laxström, 2013
+ * @license GPL2+
+ */
+
+( function ( $, mw ) {
+ 'use strict';
+
+ mw.translate = mw.translate || {};
+
+ mw.translate = $.extend( mw.translate, {
+ /**
+ * Formats some common wikitext elements
+ * @param {String} text Message text
+ * @param {String} [key] Message key
+ * @return {String} Formatted text in html
+ */
+ formatMessageGently: function ( text, key ) {
+ // Try to keep simple.
+ text = $( '<div>' ).text( text ).html();
+
+ // Hack for page translation page titles
+ if ( key && key.match( /\/Page_display_title$/ ) ) {
+ text = '=' + text + '=';
+ }
+
+ text = text.replace( /^(=+)(.*?)(=+)/, function (
match, p1, p2, p3 ) {
+ var len = Math.min( p1.length, p3.length, 6 );
+ return $( '<div>' ).append( $( '<h' + len + '>'
).html( p2 ) ).html();
+ } );
+
+ text = text.replace( /(^\*.*(\n|$))+/gm, function (
match ) {
+ match = match.replace( /^\*(.*)/gm, function (
match, p1 ) {
+ return $( '<div>' ).append( $( '<li>'
).html( p1 ) ).html();
+ } );
+ return $( '<div>' ).append( $( '<ul>' ).html(
match ) ).html();
+ } );
+
+ text = text.replace( /(^#.*(\n|$))+/gm, function (
match ) {
+ match = match.replace( /^#(.*)/gm, function (
match, p1 ) {
+ return $( '<div>' ).append( $( '<li>'
).html( p1 ) ).html();
+ } );
+ return $( '<div>' ).append( $( '<ol>' ).html(
match ) ).html();
+ } );
+
+ text = text.replace( /\[\[(.+?)\|(.+?)\]\]/g, function
( match, p1, p2 ) {
+ var link = $( '<a>' ).html( p2 ).prop( 'href',
mw.util.wikiGetlink( p1 ) );
+ return $( '<div>' ).append( link ).html();
+ } );
+
+ text = text.replace( /\[\[(.+?)\]\]/g, function (
match, p1 ) {
+ var link = $( '<a>' ).html( p1 ).prop( 'href',
mw.util.wikiGetlink( p1 ) );
+ return $( '<div>' ).append( link ).html();
+ } );
+
+ text = text.replace( /\[([^ ]+) (.+?)\]/g, function (
match, p1, p2 ) {
+ var link = $( '<a>' ).html( p2 ).prop( 'href',
p1 );
+ return $( '<div>' ).append( link ).html();
+ } );
+
+ text = text.replace( /'''(.+?)'''/g, function ( match,
p1 ) {
+ return $( '<div>' ).append( $( '<b>' ).html( p1
) ).html();
+ } );
+
+ text = text.replace( /''(.+?)''/g, function ( match, p1
) {
+ return $( '<div>' ).append( $( '<i>' ).html( p1
) ).html();
+ } );
+
+ text = text.replace( /\n\n/gm, '<br />' );
+ return text;
+ }
+ } );
+
+} ( jQuery, mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/53036
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1e131ad18008fa05784c4f67efd798a9c0598484
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits