Open mouthbow opened 3 years ago
I also like to use qtranslate-xt
in combiantion with CMB2
and was glad to find someone who had the same problems but could solve them, unlike me. But I was not able to get your solution to work yet.
If I understand you correctly, you took the createSetOfLBS
function in qtranslate-xt
and used this code to replace it with the function of the same name in the integration-cmb2-qtranslate
plugin. But the function I find in qtranslate-xt looks quite differently
/**
* @since 3.4.8
*/
this.createSetOfLSB = function () {
return qtx.createSetOfLSBwith(qTranslateConfig.lsb_style_wrap_class + ' widefat');
};
and the function it calls looks like that:
/**
* @since 3.3.2
*/
this.createSetOfLSBwith = function (lsb_style_extra_wrap_classes) {
const langSwitchWrap = qtranxj_ce('ul', {className: 'qtranxs-lang-switch-wrap ' + lsb_style_extra_wrap_classes});
const langs = qTranslateConfig.language_config;
if (!qTranslateConfig.tabSwitches)
qTranslateConfig.tabSwitches = {};
for (const lang in langs) {
const lang_conf = langs[lang];
const flag_location = qTranslateConfig.flag_location;
const li_title = qTranslateConfig.strings.ShowIn + lang_conf.admin_name + ' [:' + lang + ']';
const tabSwitch = qtranxj_ce('li', {
lang: lang,
className: 'qtranxs-lang-switch qtranxs-lang-switch-' + lang,
title: li_title,
onclick: qtx.clickSwitchLanguage
}, langSwitchWrap);
let tabItem = tabSwitch;
if (qTranslateConfig.lsb_style_subitem === 'button') {
// reuse WordPress secondary button
tabItem = qtranxj_ce('button', {className: 'button button-secondary', type: 'button'}, tabSwitch);
}
qtranxj_ce('img', {src: flag_location + lang_conf.flag}, tabItem);
qtranxj_ce('span', {innerHTML: lang_conf.name}, tabItem);
if (qTranslateConfig.activeLanguage === lang) {
tabSwitch.classList.add(qTranslateConfig.lsb_style_active_class);
$(tabSwitch).find('.button').addClass('active');
}
if (!qTranslateConfig.tabSwitches[lang])
qTranslateConfig.tabSwitches[lang] = [];
qTranslateConfig.tabSwitches[lang].push(tabSwitch);
}
if (!qTranslateConfig.hide_lsb_copy_content) {
const tab = qtranxj_ce('li', {className: 'qtranxs-lang-copy'}, langSwitchWrap);
const btn = qtranxj_ce('button', {
className: 'button-secondary',
type: 'button',
title: qTranslateConfig.strings.CopyFromAlt,
onclick: qtx.toggleCopyFrom
}, tab);
qtranxj_ce('span', {innerHTML: qTranslateConfig.strings.CopyFrom}, btn);
}
return langSwitchWrap;
};
Is your solution still working? And if so, could you please publish the new code here?
Did you mark the above code you posted above correctly? Because there is a comment in there that irritates me and shouldnt be in the compressed js.
Did you accidentally enclose the above code in two instead of three ` characters and if so could you please correct it?
Did you just edit the minified code of the main.js
in integration-cmb2-qtranslate
or the unminfied main.js
and compressend by running gulp tasks? And if you used gulp , how did you make it work?
I would be very happy to receive an answer to my questions. Muchas gracias de antemano.
Hi, CMB2 is a popular plugin for Custom Post Type (300k installations). I was using CMB2-qTranslate plugin to integrate CMB2 with q-translate-x. https://wordpress.org/plugins/integration-cmb2-qtranslate/ But the problem was that this integration plugin didn't work with q-translate-xt (last update was 5 years ago). So I tried to use Custom Fields configuration in q-translate-xt config but it didn't work and I don't know why: I tried with id and with class name with no luck. So I focused in fixing the existing integration plugin and I got it. That's the reason I want to share here just in case anyone needs the same. The only thing to do is edit main.js and change createSetOfLSB function with this one. (is a copy of the function in q-translate-xt as the original plugin did). Sorry for my english, Im spanish.
createSetOfLSB: function() { var langSwitchWrap=qtranxj_ce('ul', {className: qTranslateConfig.lsb_style_wrap_class}); var langs = qTranslateConfig.language_config; if (!qTranslateConfig.tabSwitches) qTranslateConfig.tabSwitches = {}; for (var lang in langs) { var lang_conf = langs[lang]; var flag_location = qTranslateConfig.flag_location; var li_title = qTranslateConfig.strings.ShowIn + lang_conf.admin_name + ' [:' + lang + ']'; var tabSwitch = qtranxj_ce('li', { lang: lang, className: 'qtranxs-lang-switch qtranxs-lang-switch-' + lang, title: li_title, onclick: qTranslateConfig.qtx.clickSwitchLanguage }, langSwitchWrap); var tabItem = tabSwitch; if (qTranslateConfig.lsb_style_subitem === 'button') { // reuse WordPress secondary button tabItem = qtranxj_ce('button', {className: 'button button-secondary', type: 'button'}, tabSwitch); } qtranxj_ce('img', {src: flag_location + lang_conf.flag}, tabItem); qtranxj_ce('span', {innerHTML: lang_conf.name}, tabItem); if (qTranslateConfig.activeLanguage === lang) { tabSwitch.classList.add(qTranslateConfig.lsb_style_active_class); $(tabSwitch).find('.button').addClass('active'); } if (!qTranslateConfig.tabSwitches[lang]) qTranslateConfig.tabSwitches[lang] = []; qTranslateConfig.tabSwitches[lang].push(tabSwitch); } if (!qTranslateConfig.hide_lsb_copy_content) { var tab = qtranxj_ce('li', {className: 'qtranxs-lang-copy'}, langSwitchWrap); var btn = qtranxj_ce('button', { className: 'button button-secondary', type: 'button', title: qTranslateConfig.strings.CopyFromAlt, onclick: qTranslateConfig.qtx.toggleCopyFrom }, tab); qtranxj_ce('span', {innerHTML: qTranslateConfig.strings.CopyFrom}, btn); } return langSwitchWrap; }
Also, I think that would be great that someone used to publish plugins modify the original and make available to everyone.
Thanks to this team for recovering this great translation plugin.