Use I18n-JS rather than rails-i18n in .js.erb files

This commit is contained in:
Sebastian Serth
2023-12-22 00:49:07 +01:00
committed by Sebastian Serth
parent d6c4df1bac
commit 34aac83909
3 changed files with 11 additions and 11 deletions

View File

@ -94,7 +94,7 @@ CodeOceanEditorFlowr = {
var body = resultTile.find('.card-body'); var body = resultTile.find('.card-body');
body.html(result.body); body.html(result.body);
body.append('<a target="_blank" href="' + questionUrl + '" class="btn btn-primary">' + body.append('<a target="_blank" href="' + questionUrl + '" class="btn btn-primary">' +
'<%= I18n.t('exercises.implement.flowr.go_to_question') %></a>'); `${I18n.t('exercises.implement.flowr.go_to_question')}</a>`);
body.find('.btn').on('click', CodeOceanEditor.createEventHandler('editor_flowr_click_question', questionUrl)); body.find('.btn').on('click', CodeOceanEditor.createEventHandler('editor_flowr_click_question', questionUrl));
flowrHintBody.append(resultTile); flowrHintBody.append(resultTile);

View File

@ -92,9 +92,9 @@ $(document).on('turbolinks:load', function() {
.style("left", event.pageX - 50 + "px") .style("left", event.pageX - 50 + "px")
.style("top", event.pageY + 50 + "px") .style("top", event.pageY + 50 + "px")
.style("display", "inline-block") .style("display", "inline-block")
.html("<%= I18n.t('activerecord.models.exercise.one') %> ID: " + d.exercise_id + "<br>" + .html(`${I18n.t('activerecord.models.exercise.one')} ID: ${d.exercise_id}<br>` +
"<%= I18n.t('activerecord.attributes.exercise.title') %>: " + d.exercise_title + "<br>" + `${I18n.t('activerecord.attributes.exercise.title')}: ${d.exercise_title}<br>` +
"<%= I18n.t('exercises.statistics.average_worktime') %>: " + d.working_time + "s"); `${I18n.t('exercises.statistics.average_worktime')}: ${d.working_time}s`);
}) })
.on("mouseout", function () { .on("mouseout", function () {
tooltip.style("display", "none"); tooltip.style("display", "none");
@ -174,8 +174,8 @@ $(document).on('turbolinks:load', function() {
var template = '<tr data-id="' + exercise.id + '">' + var template = '<tr data-id="' + exercise.id + '">' +
'<td><span class="fa-solid fa-bars"></span></td>' + '<td><span class="fa-solid fa-bars"></span></td>' +
'<td>' + exercise.title + '</td>' + '<td>' + exercise.title + '</td>' +
`<td><a href="${Routes.exercise_path(exercise.id)}"><%= I18n.t('shared.show') %></td>` + `<td><a href="${Routes.exercise_path(exercise.id)}">${I18n.t('shared.show')}</td>` +
'<td><a class="remove-exercise" href="#"><%= I18n.t('shared.destroy') %></td></tr>'; `<td><a class="remove-exercise" href="#">${I18n.t('shared.destroy')}</td></tr>`;
exerciseList.find('tbody').append(template); exerciseList.find('tbody').append(template);
$('#exercise-list').find('option[value="' + exercise.id + '"]').prop('selected', true); $('#exercise-list').find('option[value="' + exercise.id + '"]').prop('selected', true);
} }

View File

@ -100,7 +100,7 @@ $(document).on('turbolinks:load', function () {
event.preventDefault(); event.preventDefault();
var fileUrl = $(event.target).data('file-url'); var fileUrl = $(event.target).data('file-url');
if (confirm('<%= I18n.t('shared.confirm_destroy') %>')) { if (confirm(I18n.t('shared.confirm_destroy'))) {
var jqxhr = $.ajax({ var jqxhr = $.ajax({
// normal file path (without json) would destroy the context object (the exercise) as well, due to redirection // normal file path (without json) would destroy the context object (the exercise) as well, due to redirection
// to the context after the :destroy action. // to the context after the :destroy action.
@ -312,7 +312,7 @@ $(document).on('turbolinks:load', function () {
new_execution_environment = $('#exercise_execution_environment_id').val(); new_execution_environment = $('#exercise_execution_environment_id').val();
if (new_execution_environment == '' && !$('#exercise_unpublished').prop('checked')) { if (new_execution_environment == '' && !$('#exercise_unpublished').prop('checked')) {
if (confirm('<%= I18n.t('exercises.form.unpublish_warning') %>')) { if (confirm(I18n.t('exercises.form.unpublish_warning'))) {
$('#exercise_unpublished').prop('checked', true); $('#exercise_unpublished').prop('checked', true);
} else { } else {
return $('#exercise_execution_environment_id').val(old_execution_environment).trigger("chosen:updated"); return $('#exercise_execution_environment_id').val(old_execution_environment).trigger("chosen:updated");
@ -325,11 +325,11 @@ $(document).on('turbolinks:load', function () {
var observeUnpublishedState = function () { var observeUnpublishedState = function () {
$('#exercise_unpublished').on('change', function () { $('#exercise_unpublished').on('change', function () {
if ($('#exercise_unpublished').prop('checked')) { if ($('#exercise_unpublished').prop('checked')) {
if (!confirm('<%= I18n.t('exercises.form.unpublish_warning') %>')) { if (!confirm(I18n.t('exercises.form.unpublish_warning'))) {
$('#exercise_unpublished').prop('checked', false); $('#exercise_unpublished').prop('checked', false);
} }
} else if ($('#exercise_execution_environment_id').val() == '') { } else if ($('#exercise_execution_environment_id').val() == '') {
alert('<%= I18n.t('exercises.form.no_execution_environment_selected') %>'); alert(I18n.t('exercises.form.no_execution_environment_selected'));
$('#exercise_unpublished').prop('checked', true); $('#exercise_unpublished').prop('checked', true);
} }
}) })
@ -356,7 +356,7 @@ $(document).on('turbolinks:load', function () {
$messageDiv.removeClass('export-failure'); $messageDiv.removeClass('export-failure');
$messageDiv.html('<%= I18n.t('exercises.export_codeharbor.checking_codeharbor') %>'); $messageDiv.html(I18n.t('exercises.export_codeharbor.checking_codeharbor'));
$actionsDiv.html('<div class="spinner-border"></div>'); $actionsDiv.html('<div class="spinner-border"></div>');
return $.ajax({ return $.ajax({