다국어 지원

폴더 구조 주의

  • index.md 파일과 spec/spec.md 파일을 만들고 싶은 경우
docs/
 ㄴ index.md
 ㄴ spec/
   ㄴ spec.md 

이런 구조로 만들면 site 폴더에는 이렇게 생김

docs/
 ㄴ index.md
 ㄴ spec/
   ㄴ spec/
     ㄴ index.md 

docs_structure 가 suffix 든 folder 든 최종 site 는 위와 같다.

Languages.default 주의


```yml

plugins:
  - search
  - i18n:
      docs_structure: folder
      languages:
        - locale: en
          name: English
          default: true
          build: true
          site_name: "Manual"
          nav:
            - Home: en/index.md
            - Spec: en/Spec/index.md

en 이 default 로 설정되는 경우, site 폴더에 /en 폴더는 생성되지 않는다. 따라서 main.js 파일에 다음 부분이 수정된다.


//const indexPath = path.join(__dirname, 'site', language, 'index.html');
const indexPath = language === 'en'
  ? path.join(__dirname, 'site', 'index.html')
  : path.join(__dirname, 'site', language, 'index.html');

최종 파일은 다음과 같다.


const { app, BrowserWindow } = require('electron');
const path = require('path');
const fs = require('fs');  
function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 1024,
    height: 768,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: false
    }
  });  
  mainWindow.webContents.on('did-finish-load', () => {
    //mainWindow.webContents.openDevTools();
  });  
  let language = 'en';
  const args = process.argv.slice(2);
  if (args.includes('--lang=ko')) {
    language = 'ko';
  } else if (args.includes('--lang=zh')) {
    language = 'zh';
  } else if (args.includes('--lang=ja')) {
    language = 'ja';
  }
  
  const indexPath = language === 'en'
  ? path.join(__dirname, 'site', 'index.html')
  : path.join(__dirname, 'site', language, 'index.html');
  console.log('Loading file from:', indexPath);  
  if (fs.existsSync(indexPath)) {
    mainWindow.loadFile(indexPath).catch(err => {
      console.error('Failed to load file:', err);
    });
  } else {
    console.error('File does not exist:', indexPath);
  }
  mainWindow.webContents.on('new-window', (event, url) => {
    event.preventDefault();
    const parsedUrl = new URL(url);
    const newPath = path.join(__dirname, 'site', parsedUrl.pathname);
    if (fs.existsSync(newPath)) {
      mainWindow.loadFile(newPath).catch(err => {
        console.error('Failed to load file:', err);
      });
    } else {
      console.error('File does not exist:', newPath);
    }
  });
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});
app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});