Skip to content

Enable localization + Properly passing values to JS #8

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added languages/nrkbetaquiz-cs_CZ.mo
Binary file not shown.
84 changes: 84 additions & 0 deletions languages/nrkbetaquiz-cs_CZ.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
msgid ""
msgstr ""
"Project-Id-Version: NRKBeta Know2Comment\n"
"POT-Creation-Date: 2017-04-30 16:41+0200\n"
"PO-Revision-Date: 2017-04-30 16:41+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"X-Generator: Poedit 2.0.1\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: nrkbetaquiz.php\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"

#: nrkbetaquiz.php:31
msgid "You have not answered the quiz correctly. Try again."
msgstr "Tato odpověď není správná. Zkuste to znovu."

#: nrkbetaquiz.php:41
msgid ""
"Would you like to comment? Please answer some quiz questions from the story."
msgstr "Chcete se zapojit do diskuse? Prosím odpovězte na otázky níže."

#: nrkbetaquiz.php:43
msgid "We care about our comments."
msgstr "Záleží nám na kvalitě této diskuse."

#: nrkbetaquiz.php:44
msgid ""
"That's why we want to make sure that everyone who comments have actually "
"read the story."
msgstr ""
"A proto si chceme být jisti, že každý komentující četl článek, který "
"komentuje."

#: nrkbetaquiz.php:45
msgid "Answer a couple of questions from the story to unlock the comment form."
msgstr "Odpovězte na pár otázek z články, abyste odemkli formulář."

#: nrkbetaquiz.php:47
#, php-format
msgid "Please %1$senable javascript%2$s to comment"
msgstr "Prosím %1$spovolte javascript%2$s pro komentáře"

#: nrkbetaquiz.php:58
msgid "Add question +"
msgstr "Přidat otázku +"

#: nrkbetaquiz.php:59
msgid "Correct"
msgstr "Správně"

#: nrkbetaquiz.php:60
msgid "Answer"
msgstr "Odpověď"

#: nrkbetaquiz.php:63
msgid "Question"
msgstr "Otázka"

#. Plugin Name of the plugin/theme
msgid "NRKBeta Know2Comment"
msgstr "NRKBeta Know2Comment"

#. Plugin URI of the plugin/theme
msgid "https://nrkbeta.no/"
msgstr "https://nrkbeta.no/"

#. Description of the plugin/theme
msgid "Require the user to answer a quiz to be able to post comments."
msgstr "Uživatel musí odpovědět na kvíz, aby mohl přidat komentáře."

#. Author of the plugin/theme
msgid "Henrik Lied and Eirik Backer, Norwegian Broadcasting Corporation"
msgstr "Henrik Lied and Eirik Backer, Norwegian Broadcasting Corporation"
82 changes: 82 additions & 0 deletions languages/nrkbetaquiz.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#, fuzzy
msgid ""
msgstr ""
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"Project-Id-Version: NRKBeta Know2Comment\n"
"POT-Creation-Date: 2017-04-30 16:41+0200\n"
"PO-Revision-Date: 2017-04-30 15:17+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.1\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: nrkbetaquiz.php\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"

#: nrkbetaquiz.php:31
msgid "You have not answered the quiz correctly. Try again."
msgstr ""

#: nrkbetaquiz.php:41
msgid ""
"Would you like to comment? Please answer some quiz questions from the story."
msgstr ""

#: nrkbetaquiz.php:43
msgid "We care about our comments."
msgstr ""

#: nrkbetaquiz.php:44
msgid ""
"That's why we want to make sure that everyone who comments have actually "
"read the story."
msgstr ""

#: nrkbetaquiz.php:45
msgid "Answer a couple of questions from the story to unlock the comment form."
msgstr ""

#: nrkbetaquiz.php:47
#, php-format
msgid "Please %1$senable javascript%2$s to comment"
msgstr ""

#: nrkbetaquiz.php:58
msgid "Add question +"
msgstr ""

#: nrkbetaquiz.php:59
msgid "Correct"
msgstr ""

#: nrkbetaquiz.php:60
msgid "Answer"
msgstr ""

#: nrkbetaquiz.php:63
msgid "Question"
msgstr ""

#. Plugin Name of the plugin/theme
msgid "NRKBeta Know2Comment"
msgstr ""

#. Plugin URI of the plugin/theme
msgid "https://nrkbeta.no/"
msgstr ""

#. Description of the plugin/theme
msgid "Require the user to answer a quiz to be able to post comments."
msgstr ""

#. Author of the plugin/theme
msgid "Henrik Lied and Eirik Backer, Norwegian Broadcasting Corporation"
msgstr ""
5 changes: 2 additions & 3 deletions nrkbetaquiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ document.addEventListener('DOMContentLoaded', function(){

var buildQuiz = function(quizNode){
var formNode = quizNode.nextElementSibling;
var errorText = quizNode.getAttribute('data-' + NRKBCQ + '-error');
var questions = parseQuiz(quizNode.getAttribute('data-' + NRKBCQ));
var questions = parseQuiz(nrkbcq.questions);
var correctId = NRKBCQ + location.pathname + questions.map(function(q){return q.correct}).join('');
var errorNode = document.createElement('h3').appendChild(document.createTextNode(errorText)).parentNode;
var errorNode = document.createElement('h3').appendChild(document.createTextNode(nrkbcq.i18n_error)).parentNode;
var container = document.createElement('div');

if(localStorage.getItem(correctId) === correctId){ //Skip quiz if already solved
Expand Down
40 changes: 29 additions & 11 deletions nrkbetaquiz.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
<?php
/*
Plugin Name: NRKBeta Know2Comment
Version: 1.0.0
Version: 1.0.1
Plugin URI: https://nrkbeta.no/
Author: Henrik Lied and Eirik Backer, Norwegian Broadcasting Corporation
Description: Require the user to answer a quiz to be able to post comments.
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

define('NRKBCQ', 'nrkbetaquiz');
define('NRKBCQ_NONCE', NRKBCQ . '-nonce');

// Load textdomain
add_action( 'init', 'nrkbetaquiz_localize_plugin' );
function nrkbetaquiz_localize_plugin() {
load_plugin_textdomain( 'nrkbetaquiz', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

add_action('wp_enqueue_scripts', function(){
wp_enqueue_script(NRKBCQ, plugins_url('nrkbetaquiz.js', __FILE__));
wp_enqueue_style(NRKBCQ, plugins_url('nrkbetaquiz.css', __FILE__));
if( comments_open() ) {
global $post;
wp_register_script( NRKBCQ, plugins_url('nrkbetaquiz.js', __FILE__) );
wp_enqueue_script( NRKBCQ);
$params = array(
'questions' => esc_attr(rawurlencode(json_encode(get_post_meta($post->ID, NRKBCQ)))),
'i18n_error' => __('You have not answered the quiz correctly. Try again.', NRKBCQ),
);
wp_localize_script( NRKBCQ, 'nrkbcq', $params );
wp_enqueue_style(NRKBCQ, plugins_url('nrkbetaquiz.css', __FILE__));
}
});

add_action('comment_form_before', 'nrkbetaquiz_form');
function nrkbetaquiz_form(){ ?>
<div class="<?php echo NRKBCQ; ?>"
data-<?php echo NRKBCQ; ?>="<?php echo esc_attr(rawurlencode(json_encode(get_post_meta(get_the_ID(), NRKBCQ)))); ?>"
data-<?php echo NRKBCQ; ?>-error="<?php echo esc_attr(__('You have not answered the quiz correctly. Try again.', NRKBCQ)); ?>">
<h2>Would you like to comment? Please answer some quiz questions from the story.</h2>
<div class="<?php echo NRKBCQ; ?>">
<h2><?php _e('Would you like to comment? Please answer some quiz questions from the story.', NRKBCQ); ?></h2>
<p>
We care about our comments.
That's why we want to make sure that everyone who comments have actually read the story.
Answer a couple of questions from the story to unlock the comment form.
<?php _e('We care about our comments.', NRKBCQ); ?>
<?php _e("That's why we want to make sure that everyone who comments have actually read the story.", NRKBCQ); ?>
<?php _e('Answer a couple of questions from the story to unlock the comment form.', NRKBCQ); ?>
</p>
<noscript>Please <a href="http://enable-javascript.com/" target="_blank" style="text-decoration:underline">enable javascript</a> to comment</noscript>
<noscript><?php printf( __( 'Please %1$senable javascript%2$s to comment', NRKBCQ ) , '<a href="http://enable-javascript.com/" target="_blank" style="text-decoration:underline">', '</a>' ); ?></noscript>
</div>
<?php }

Expand Down