Home Explore Blog CI



neovim

2nd chunk of `src/nvim/po/CMakeLists.txt`
b14af83b97198e17a4c2447153f521845f1d074deb2712400000000100000e77
   VERBATIM
    DEPENDS ${NVIM_SOURCES} nvim_bin nvim_runtime_deps)

  set(LANGUAGE_MO_FILES)
  set(UPDATE_PO_TARGETS)

  macro(BuildMo name)
    set(poFile ${CMAKE_CURRENT_SOURCE_DIR}/${name}.po)
    set(moFile ${CMAKE_CURRENT_BINARY_DIR}/${name}.mo)

    add_custom_command(
      OUTPUT ${moFile}
      COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${moFile} ${poFile}
      DEPENDS ${poFile} ${NVIM_POT})

    install_helper(
      FILES ${moFile}
      DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${name}/LC_MESSAGES
      RENAME ${PROJECT_NAME}.mo)

    list(APPEND LANGUAGE_MO_FILES ${moFile})
  endmacro()

  macro(CheckPo name)
    set(poFile ${CMAKE_CURRENT_SOURCE_DIR}/${name}.po)

    add_custom_target(check-po-${name}
      COMMAND $<TARGET_FILE:nvim_bin> -u NONE -n -e
          -S ${CMAKE_CURRENT_SOURCE_DIR}/check.vim
          -c "if error == 0 | q | endif" -c cq ${poFile} ||
          ${CMAKE_COMMAND} -E echo "${name}.po failed the check."
      COMMENT "Checking ${name}.po"
      VERBATIM
      DEPENDS ${poFile})
  endmacro()

  macro(BuildPoIconvGenericWithCharset
      lang inputName outputName inputEnc outputEnc outputCharSet)
    set(inputFile ${CMAKE_CURRENT_SOURCE_DIR}/${inputName}.po)
    set(outputFile ${CMAKE_CURRENT_SOURCE_DIR}/${outputName}.po)

    add_custom_target(update-po-${lang}
      COMMAND ${CMAKE_COMMAND}
        -D ICONV_PRG=${ICONV_PRG}
        -D INPUT_FILE=${inputFile}
        -D OUTPUT_FILE=${outputFile}
        -D INPUT_ENC=${inputEnc}
        -D OUTPUT_ENC=${outputEnc}
        -D OUTPUT_CHARSET=${outputCharSet}
        -P ${PROJECT_SOURCE_DIR}/cmake/ConvertPo.cmake
      COMMENT "Updating ${outputName}.po"
      DEPENDS ${inputFile})

    CheckPo(${outputName})

    list(APPEND UPDATE_PO_TARGETS update-po-${lang})
  endmacro()

  macro(BuildPoIconvGeneric lang inputName outputName inputEnc outputEnc)
    # Most of the time, the output charset is the same as the iconv output
    # encoding.
    BuildPoIconvGenericWithCharset(
      ${lang} ${inputName} ${outputName} ${inputEnc} ${outputEnc} ${outputEnc})
  endmacro()

  macro(BuildPoIconv name inputEnc outputEnc)
    set(lang ${name}.${outputEnc})
    set(inputName ${name})

    if(outputEnc STREQUAL utf-8)
      set(outputName ${name}.UTF-8)
    else()
      set(outputName ${lang})
    endif()

    BuildPoIconvGeneric(
      ${lang} ${inputName} ${outputName} ${inputEnc} ${outputEnc})
  endmacro()

  # Create some translations from others.
  if(";${LANGUAGES};" MATCHES ";ja;")
    BuildPoIconv(ja utf-8 euc-jp)
    BuildMo(ja.euc-jp)
  endif()

  if(";${LANGUAGES};" MATCHES ";cs;")
    BuildPoIconv(cs ISO-8859-2 cp1250)
    BuildMo(cs.cp1250)
  endif()

  if(";${LANGUAGES};" MATCHES ";sk;")
    BuildPoIconv(sk ISO-8859-2 cp1250)
    BuildMo(sk.cp1250)
  endif()

  add_custom_target(update-po-nb
    COMMAND ${CMAKE_COMMAND} -E copy
        ${CMAKE_CURRENT_SOURCE_DIR}/no.po ${CMAKE_CURRENT_SOURCE_DIR}/nb.po
    DEPENDS no.po)
  list(APPEND UPDATE_PO_TARGETS update-po-nb)
  if(";${LANGUAGES};" MATCHES ";no;")
    CheckPo(nb)
    BuildMo(nb)
  endif()

  foreach(LANGUAGE ${LANGUAGES})
    set(poFile "${CMAKE_CURRENT_SOURCE_DIR}/${LANGUAGE}.po")

    add_custom_target(update-po-${LANGUAGE}
      COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} -q --update --backup=none --sort-by-file
      ${poFile} ${NVIM_POT}
      COMMENT "Updating ${LANGUAGE}.po"
      DEPENDS ${NVIM_POT})

    CheckPo(${LANGUAGE})

    list(APPEND UPDATE_PO_TARGETS update-po-${LANGUAGE})

    BuildMo(${LANGUAGE})
  endforeach()

  add_custom_target(nvim_translations DEPENDS ${LANGUAGE_MO_FILES})
  add_custom_target(update-po DEPENDS ${UPDATE_PO_TARGETS})
  add_dependencies(nvim nvim_translations)
endif()

Title: Macros for Building and Updating Translations
Summary
This section defines CMake macros for building and updating translations. It includes macros for creating MO files from PO files, checking PO files for errors using a custom Vim script, and converting PO files between different encodings using iconv. It also handles specific cases, such as creating translations from existing ones (e.g., ja from euc-jp) and updating PO files using `msgmerge`. Finally, it creates custom targets for building all translations and updating PO files.