Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add i18n #27

Merged
merged 18 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@ This is a web interface for [Plagiabot's Copyright RC feed](https://en.wikipedia

This application makes of use [Wikimedia-slimapp](https://github.com/wikimedia/wikimedia-slimapp) library and uses Twig as its templating library.

##### To add a new translation message:
1. Add it to en.json
2. Call it in Twig as <code>{{ '<message-key>'|message }}</code>. If the message contains any html, you need to add the <code>|raw</code> param after 'message'.
3. To use a translation message in JS, add it as a JS var in templates/base.html. Then simply access it in JS.
4. To call it in PHP:
<code>$this->i18nContext->message( '<message-key>' )</code>



3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"oyejorge/less.php": "~1.5",
"mediawiki/oauthclient": "~0.1",
"wikimedia/slimapp": "dev-master",
"addwiki/mediawiki-api-base": "~2.1"
"addwiki/mediawiki-api-base": "~2.1",
"wikimedia/simplei18n": "~1.0"
},
"autoload": {
"psr-4": {
Expand Down
71 changes: 71 additions & 0 deletions public_html/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"@metadata": {
"authors": [
"Niharika Kohli",
"MusikAnimal",
"Ryan Kaldari"
]
},
"name": "CopyPatrol",
"documentation": "Documentation",
"feedback": "Feedback",
"leaderboard": "Leaderboard",
"login": "Login",
"logout": "Logout",
"header-loggedin": "You are logged in as: $1",
"form-all": "All cases",
"form-open": "Open cases",
"form-reviewed": "Reviewed cases",
"form-mine": "My reviews",
"form-drafts": "Drafts only",
"wikiprojects": "Wikiprojects",
"form-wikiprojects-placeholder": "Type Wikiproject names...",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"WikiProject" is always camelcase.

"submit": "Submit",
"page": "Page",
"diff": "Diff",
"editor": "Editor",
"review": "Review",
"review-fixed": "Page fixed",
"review-fixed-tooltip": "The edit was a copyright violation and has been reverted",
"review-false": "No action needed",
"review-false-tooltip": "The edit is a false positive, nothing needs to be done",
"review-by": "Reviewed by:",
"history": "History",
"talk": "Talk",
"contribs": "Contributions",
"record-editcount": "Edit count:",
"compare": "Compare",
"record-ithenticate": "iThenticate report",
"record-url-text": "$1 of edit ($2 words)",
"record-noeditor": "No editor found",
"record-noeditor-tooltip": "The revision may have been deleted or the data is not yet available in Labs database.",
"record-ores": "ORES score: $1",
"article": "Article",
"compare-article-loading": "Loading article revision...",
"compare-source-loading": "Loading possible copyvio source...",
"footer-loadmore": "Load More",
"footer-nomore": "No more records!",
"footer-broughtby": "Brought to you by $1",
"footer-commtech": "Community Tech",
"footer-poweredby": "Powered by $1 and $2",
"source": "Source",
"phabricator": "Phabricator",
"footer-imageattr": "Image attribution",
"lboard-title": "Leaderboard",
"lboard-week": "Cases closed in the<br/> last 7 days",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded linebreaks don't really work for translation, since the translators won't know where to put the linebreaks to make sure things wrap correctly. Danny originally wanted this done so that all the columns lined up right, but we can probably figure out a better way to do this in a future commit. For now, let's just remove the line breaks and let the lines wrap naturally (even if they don't all line up perfectly).

"lboard-month": "Cases closed in the<br/> last 30 days",
"lboard-alltime": "All time<br/> cases closed",
"lboard-back": "Back to CopyPatrol",
"close": "Close",
"imageattr-title": "Image attribution",
"imageattr-logo": "CopyPatrol logo",
"public-domain": "public domain",
"open-font-license": "Open Font License",
"imageattr-paragraph1": "$1 available to the $2 courtesy of $3 and the $4",
"imageattr-paragraph2": "$1 released under the $2 courtesy of $3",
"alert-testing": "This is a staging environment. Please do not use this tool to record your reviews. For the actual CopyPatrol tool, please use $1.",
"js-unauthorized": "You need to be logged in to be able to review.",
"js-dberror": "There was an error in connecting to database.",
"js-undo-own-only": "You can only undo your own reviews.",
"js-unknown-error": "An unknown error occurred when loading results. Please try again."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing is I would avoid including links and markup in the messages. E.g. you get rid of footer-source and instead just have "source": "Source" and our HTML, <a href="https://github.com/wikimedia/PlagiabotWeb">{{ 'source'|message }}</a>. The markup is not translatable and there's a chance someone might unintentionally break it.

And for footer-poweredby you could use: Powered by $1 and $2 since EranBot and Turnitin are also not translatable. If they are, make a separate message for turnitin then in our HTML:
{{ 'footer-poweredby'|message | ( <a href="https://en.wikipedia.org/wiki/Wikipedia:Turnitin">{{ 'turnitin'|message }}</a> | <a href="https://en.wikipedia.org/wiki/User:EranBot">{{ 'EranBot'|message }}</a> }} (this is pseudocode, not sure how SimpleI18n works)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it should be https://github.com/wikimedia/CopyPatrol

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I also fixed some links in Image attribution modal. I didn't break it up into 12 messages but 8 instead.
The link in footer is https://github.com/wikimedia/CopPatrol only. Did you see otherwise anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, simpleI18n doesn't support the sort of markup you were suggesting above so I resorted to break out the text.

}
26 changes: 13 additions & 13 deletions public_html/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
$reviewerNode.find( '.reviewer-timestamp' ).text( ret.timestamp );
$reviewerNode.fadeIn( 'slow' );
} else if ( ret.error === 'Unauthorized' ) {
window.alert( 'You need to be logged in to be able to review.' );
window.alert( jsUnauthorized );
// go back to initial state
setReviewState( id, 'open' );
} else {
window.alert( 'There was an error in connecting to database.' );
window.alert( jsDbError );
setReviewState( id, 'open' );
}

Expand All @@ -99,10 +99,10 @@
$reviewerNode.fadeOut( 'slow' );
setReviewState( id, 'open' );
} else if ( ret.error === 'db-error' ) {
window.alert( 'There was an error in connecting to database.' );
window.alert( jsDbError );
setReviewState( id, oldStatus ); // revert back to old state
} else {
window.alert( 'You can only undo your own reviews.' );
window.alert( jsUndoOwnOnly );
setReviewState( id, oldStatus );
}

Expand Down Expand Up @@ -145,11 +145,11 @@
if ( $newRecords.find( '.js-record' ).length ) {
$( '.record-container' ).append( $newRecords.html() );
} else {
$( '.js-load-more' ).replaceWith( '<p>No more records!</p>' );
$( '.js-load-more' ).replaceWith( '<p>' + jsNoMore + '</p>' );
}
} ).fail( function () {
alert( 'An unknown error occurred when loading results. Please try again.' );
$( '#btn-load-more' ).text( 'Load More' ).removeClass( 'btn-loading' );
alert( jsUnknownError );
$( '#btn-load-more' ).text( jsLoadMore ).removeClass( 'btn-loading' );
} );
}

Expand Down Expand Up @@ -201,7 +201,7 @@
}
} else {
// use API-provided error message, otherwise a blanket unknown error message as it could be unrelated to the API
var errorMessage = ret.error && ret.error.info ? ret.error.info : 'An unknown error occurred.';
var errorMessage = ret.error && ret.error.info ? ret.error.info : jsUnknownError;
$( compareDiv ).find( '.compare-pane-body' ).html( '<span class="text-danger">' + errorMessage + '</span>' );
}
} );
Expand All @@ -222,7 +222,7 @@
url: 'https://en.wikipedia.org/w/api.php',
dataType: 'jsonp',
delay: 200,
data: function( search ) {
data: function ( search ) {
return {
action: 'opensearch',
namespace: '4',
Expand All @@ -232,22 +232,22 @@
}
},
// format API data in the way Select2 wants it
processResults: function( data ) {
processResults: function ( data ) {
var results = data[1];
return {
results: results.map( function( elem ) {
results: results.map( function ( elem ) {
var title = elem.replace( /^Wikipedia:WikiProject /, '' );
// don't show WikiProject subpages
return !/\//g.test( title ) ? {
id: title.replace( / /g, '_' ),
text: title
} : {};
})
} )
};
},
cache: true
},
placeholder: 'Type WikiProject names...',
placeholder: formWikiprojectsPlaceholder,
maximumSelectionLength: 10,
minimumInputLength: 1
};
Expand Down