Skip to content

Commit

Permalink
move subdomain blocker to startTranslationCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Oct 22, 2024
1 parent 8a590ef commit 7cca013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 0 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ async function getTranslations(window, apiKey, optsArgs = {}) {
await createLanguageSelect(window, optsArgs);
}

if (!window.isWorker && optsArgs.translationMode == "subdomain") {
await renderSelectorState(window, { shouldUpdateActiveLang: true, delay: 0, shouldLog: false })

// dont translate anything on original site
if (!window.activeSubdomain) {
return window;
} else {
window.globalseoActiveLang = window.activeSubdomain;
}
}

// handle google translate
if (isBrowser() && (window.document.querySelector('html.translated-ltr') || window.document.querySelector('html.translated-rtl'))) return;

Expand Down
12 changes: 12 additions & 0 deletions utils/translation/startTranslationCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { getGlobalseoActiveLang, getGlobalseoOptions } = require("../configs");
const { getLanguageFromLocalStorage } = require("../languages/getSelectedLanguage");
const modifyHtmlStrings = require("./modifyHtmlStrings");
const { debounce } = require("../debounce");
const { renderSelectorState } = require("../selector/renderSelectorState");

async function startTranslationCycle(window, node, apiKey, delay, shouldOptimizeSEO = false) {
if (window.preventInitialTranslation) {
Expand All @@ -10,6 +11,17 @@ async function startTranslationCycle(window, node, apiKey, delay, shouldOptimize
};
const options = getGlobalseoOptions(window);

if (!window.isWorker && options.translationMode == "subdomain") {
await renderSelectorState(window, { shouldUpdateActiveLang: true, delay: 0, shouldLog: false })

// dont translate anything on original site
if (!window.activeSubdomain) {
return window;
} else {
window.globalseoActiveLang = window.activeSubdomain;
}
}

// replace src because nextjs will replace the whole html on rerender
if (options.translationMode == "subdomain" && window.activeSubdomain) {
// get all elements with src attribute
Expand Down

0 comments on commit 7cca013

Please sign in to comment.