Is there a way to translate the delivery date and time widget?

We are sorry, but “CC Delivery Date Selector” does not have a translation feature.

We suggest the following three alternatives.

1. Switch the display per language

Open the app > Home > “Options” > “See all” > “Display per language” in the list on the left. Turn ON “Choose the languages to enable” to choose in which languages the delivery date and time widget is shown.

2. Write both languages in the label

In the label text, write both languages, for example “配送希望日/Request Delivery Date”.

3. Change the text dynamically with JavaScript

Use the following code to change the text for each language.

// Settings
const languages = [
  {
    lang: "en",
    "#cc-date-label": "Request Delivery Date",
    "#cc-time-label": "Request Delivery Time",
    "#cc-calendar-input-column": "no request",
    "#cc-time-options": ["no request", "morning", "evening"], // Change to match your own time options.
    "#not-specified": "no request",
    "#cc-main-note-context": "notes",
    // Only if you have set delivery options
    "#slot-label": "Delivery Options",
    "#slot-body": ["Delivery", "Store pick up"],
    "#cc-calendar-slot-note pre": "this is example notes",
  },
];

const config = { attributes: true, childList: true, subtree: true };
const callback = () => {
  const locale = Shopify.locale;
  const language = languages.find((l) => l.lang === locale);
  if (!locale) return;

  const changeLabel = (elmTxt, replaceTxt) => {
    document.querySelectorAll(elmTxt).forEach((elm) => {
      switch (elmTxt) {
        case "#cc-calendar-input-column":
          const jaText = "指定しない"; // Change this text if you changed the setting.
          if (elm.value === jaText) elm.value = replaceTxt;
          break;
        case "#cc-time-options":
        case "#slot-body":
          elm
            .querySelectorAll(elmTxt === "#slot-body" ? "span" : "option")
            .forEach((o, n) => {
              if (replaceTxt[n] && o.textContent !== replaceTxt[n])
                o.textContent = replaceTxt[n];
            });
          break;
        default:
          if (elm.textContent !== replaceTxt) elm.textContent = replaceTxt;
      }
    });
  };

  Object.entries(language).forEach(([key, value]) => {
    changeLabel(key, value);
  });
};
const observer = new MutationObserver(callback);
callback();
const mTime = { start: Date.now(), end: Date.now() };
const mo = new MutationObserver(function (records) {
  mTime.start = Date.now();

  setTimeout(async () => {
    mTime.end = Date.now();
    if (mTime.end - mTime.start >= 1000) {
      callback();
    }
  }, 1000);
});

observer.observe(document.querySelector("body"), config);
Install