Answer the question
In order to leave comments, you need to log in
How to make a separate JS multilingual in Opencart (fastorder at the root)?
Hello. I really need help...
There is a store for opencart with a quick order module for JS. The file is located in the root of the site mysite.ru/fastorder/fastorder.js. It is accessed by almost all files from the product and module folders.
I can not make the text multilingual, which is in this file.
Here is the script itself from this file:
$(document).ready(function () {
$('#content').on('click' ,'.product-list .singleclick, .product-grid .singleclick, .itemcolumns .singleclick', function () {
$('.fast_order_button').css('display','block');
$('#fast_order_result').html('');
var product = $(this).parents('.product-list > div, .product-grid > div, .itemcolumns');
$('#product_name').val(product.find('.name a').text());
$('#product_price').val(product.find('.price').text());
$('#singleclick_title').text(product.find('.name a').text());
$.colorbox({
href: "#fast_order_form",
inline: true,
maxWidth:'95%',
maxHeight:'95%',
overlayClose: true,
title: " ",
opacity: 0.5,
});
});
$('.fast_order_button').on('click', function () {
var $sendparam = $(this).closest("#fast_order_form");
var product_name = $('#product_name', $sendparam).val();
var product_price = $('#product_price', $sendparam).val();
var customer_name = $('#customer_name', $sendparam).val();
var customer_phone = $('#customer_phone', $sendparam).val();
var customer_message = $('#customer_message', $sendparam).val();
var captcha = $('#captcha', $sendparam).val();
var pr = $('#pr', $sendparam).val();
$('#fast_order_result', $sendparam).text('Обрабатываем введенные данные..');
$.post('/index.php?route=module/singleclick', {
'product_name': product_name,
'product_price': product_price,
'customer_name': customer_name,
'customer_phone': customer_phone,
'captcha': captcha,
'pr': pr ,
'customer_message': customer_message
}, function (data) {
var data = $.parseJSON(data);
if ('error' in data) {
$('#fast_order_result', $sendparam).html('<span class="singleclick_error">' + data.error + '</span>');
} else {
$('#fast_order_result', $sendparam).html('<span class="singleclick_success">Заявка оформлена</span><br /><span>Мы перезвоним Вам.</span>');
$('.fast_order_button', $sendparam).css('display','none');
}
});
});
});
Answer the question
In order to leave comments, you need to log in
1. in header.tpl add a condition to the script connection in the following way:
2. copy the fast_order.js file and name it fast_order_uk.js and fast_order_en.js
Done! It remains only to translate the text into the desired language in the appropriate files.
put all the text into some kind of associative array, preferably in a separate file, from all scripts, when you need to get the text, access the file with texts through a gasket (which just knows what needs to be imported), depending on the localization, the user loads files from different localization. For example, the url should contain the presence of a lang, if a file is accessed but there is no suitable localization, issue another one that goes by default. As a result, all scripts turn to API pads with the desire to receive a certain text by key, and the pad decides whether to display the text or throw an error, saying that the text was not found, but if we don’t find it, send the requested key to the status, due to which there was a problem...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question