How to change Japanese half-width characters to full-width characters, and vice versa

Although this is the issue peculiar to Japanese, there are half-width and full-width characters in Japanese.

Therefore, I want to change half-width characters to full-width characters, and vice versa.

Hi @JIMA
I think this is bit too specialized for its own transform. However I found some Javascript online that allows you to do it in a Javascript transform.

To convert column 1 from half to full width Japanese characters:

return $(1).normalize('NFKC');

To convert column from full width to half width Japanese characters:

function convertToHalfWidth(string) {
  let characters = getCharacters(string);
  let halfWidthString = ''
  characters.forEach(character => {
    halfWidthString += mapToHankaku(character);
  });
  return halfWidthString;
}

function getCharacters(string) {
   return string.split("");
}

function mapToHankaku(character) {
  let zenHanMap = getZenkakuToHankakuMap();
  if (typeof zenHanMap[character] === 'undefined') {
    return character;
  } else {
    return zenHanMap[character];
  }
}

function getZenkakuToHankakuMap() {
  let zenHanMap = {
    'ァ': 'ァ',
    'ア': 'ア',
    'ィ': 'ィ',
    'イ': 'イ',
    'ゥ': 'ゥ',
    'ウ': 'ウ',
    'ェ': 'ェ',
    'エ': 'エ',
    'ォ': 'ォ',
    'オ': 'オ',
    'カ': 'カ',
    'ガ': 'ガ',
    'キ': 'キ',
    'ギ': 'ギ',
    'ク': 'ク',
    'グ': 'グ',
    'ケ': 'ケ',
    'ゲ': 'ゲ',
    'コ': 'コ',
    'ゴ': 'ゴ',
    'サ': 'サ',
    'ザ': 'ザ',
    'シ': 'シ',
    'ジ': 'ジ',
    'ス': 'ス',
    'ズ': 'ズ',
    'セ': 'セ',
    'ゼ': 'ゼ',
    'ソ': 'ソ',
    'ゾ': 'ゾ',
    'タ': 'タ',
    'ダ': 'ダ',
    'チ': 'チ',
    'ヂ': 'ヂ',
    'ッ': 'ッ',
    'ツ': 'ツ',
    'ヅ': 'ヅ',
    'テ': 'テ',
    'デ': 'デ',
    'ト': 'ト',
    'ド': 'ド',
    'ナ': 'ナ',
    'ニ': 'ニ',
    'ヌ': 'ヌ',
    'ネ': 'ネ',
    'ノ': 'ノ',
    'ハ': 'ハ',
    'バ': 'バ',
    'パ': 'パ',
    'ヒ': 'ヒ',
    'ビ': 'ビ',
    'ピ': 'ピ',
    'フ': 'フ',
    'ブ': 'ブ',
    'プ': 'プ',
    'ヘ': 'ヘ',
    'ベ': 'ベ',
    'ペ': 'ペ',
    'ホ': 'ホ',
    'ボ': 'ボ',
    'ポ': 'ポ',
    'マ': 'マ',
    'ミ': 'ミ',
    'ム': 'ム',
    'メ': 'メ',
    'モ': 'モ',
    'ャ': 'ャ',
    'ヤ': 'ヤ',
    'ュ': 'ュ',
    'ユ': 'ユ',
    'ョ': 'ョ',
    'ヨ': 'ヨ',
    'ラ': 'ラ',
    'リ': 'リ',
    'ル': 'ル',
    'レ': 'レ',
    'ロ': 'ロ',
    'ヮ': '',
    'ワ': 'ワ',
    // 'ヰ': '゙  ゚',
    // 'ヱ': '',
    'ヲ': 'ヲ',
    'ン': 'ン',
    'ヴ': 'ヴ',
    // 'ヵ': '',
    // 'ヶ': '',
    // 'ヷ': '',
    // 'ヸ': '',
    // 'ヹ': '',
    // 'ヺ': '',
    '・': '・',
    'ー': 'ー',
    // 'ヽ': '',
    // 'ヾ': '',
    // 'ヿ': '',
  };
  return zenHanMap;
}

return convertToHalfWidth($(1));

Perhaps there is a simpler way to do the second conversion?

See also this example .transform which does both conversions:

japanese-half-full.transform (8.1 KB)

References:

1 Like

Thank you for your quick response.
The issue is solved by using your file!

2 Likes