2011-01-20 20:45:07 +00:00
# Macro to compile po file
# It based on FindGettext.cmake files.
# The macro was adapted for PCSX2 need. Several pot file, language based on directory instead of file
# Copyright (c) 2007-2009 Kitware, Inc., Insight Consortium
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * The names of Kitware, Inc., the Insight Consortium, or the names of
# any consortium members, or of any contributors, may not be used to
# endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2021-12-12 22:42:04 +00:00
FUNCTION ( GETTEXT_CREATE_TRANSLATIONS_PCSX2 _potFile )
2021-12-12 22:27:35 +00:00
SET ( _moFiles )
2021-07-04 05:24:21 +00:00
GET_FILENAME_COMPONENT ( _potBasename ${ _potFile } NAME_WE )
GET_FILENAME_COMPONENT ( _absPotFile ${ _potFile } ABSOLUTE )
2011-01-20 20:45:07 +00:00
2021-12-12 22:38:02 +00:00
FOREACH ( _currentPoFile ${ ARGN } )
2021-07-04 05:24:21 +00:00
GET_FILENAME_COMPONENT ( _absFile ${ _currentPoFile } ABSOLUTE )
2021-12-12 22:27:35 +00:00
GET_FILENAME_COMPONENT ( _abs_PATH ${ _absFile } DIRECTORY )
2021-07-04 05:24:21 +00:00
GET_FILENAME_COMPONENT ( _lang ${ _abs_PATH } NAME_WE )
2021-12-12 22:27:35 +00:00
SET ( _moFile ${ CMAKE_CURRENT_BINARY_DIR } / ${ _lang } / ${ _potBasename } .mo )
2021-07-04 05:24:21 +00:00
IF ( APPLE )
2021-12-12 22:27:35 +00:00
# On MacOS, we have have to preprocess the po files to remove mnemonics:
2021-07-04 05:24:21 +00:00
# On Windows, menu items have "mnemonics", the items with a letter underlined that you can use with alt to select menu items. MacOS doesn't do this.
# Some languages don't use easily-typable characters, so it's common to add a dedicated character for the mnemonic (e.g. in Japanese on Windows, the File menu would be "ファイル(&F)").
# On MacOS, these extra letters in parentheses are useless and should be avoided.
2021-12-12 22:27:35 +00:00
SET ( _mnemonicless "${CMAKE_CURRENT_BINARY_DIR}/${_lang}/${_potBasename}.nomnemonic.po" )
SET ( _compileCommand
2021-07-04 05:24:21 +00:00
C O M M A N D s e d - e " \ " s / [ ( ] & [ A - Z a - z ] [ ) ] / / g \ " " " $ { _ a b s F i l e } " > " $ { _ m n e m o n i c l e s s } "
2021-12-12 22:27:35 +00:00
C O M M A N D $ { G E T T E X T _ M S G F M T _ E X E C U T A B L E } - o $ { _ m o F i l e } $ { _ m n e m o n i c l e s s }
B Y P R O D U C T S $ { _ m n e m o n i c l e s s }
)
2021-07-04 05:24:21 +00:00
ELSE ( APPLE )
2021-12-12 22:27:35 +00:00
SET ( _compileCommand
C O M M A N D $ { G E T T E X T _ M S G F M T _ E X E C U T A B L E } - o $ { _ m o F i l e } $ { _ a b s F i l e }
)
2021-07-04 05:24:21 +00:00
ENDIF ( APPLE )
2011-01-20 20:45:07 +00:00
2021-07-04 05:24:21 +00:00
IF ( _currentPoFile MATCHES "\\.git" )
continue ( )
ENDIF ( _currentPoFile MATCHES "\\.git" )
2019-01-01 07:02:34 +00:00
2021-07-04 05:24:21 +00:00
IF ( CMAKE_BUILD_PO )
2021-12-12 22:27:35 +00:00
ADD_CUSTOM_COMMAND ( OUTPUT ${ _moFile }
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ l a n g }
2021-07-04 05:24:21 +00:00
C O M M A N D $ { G E T T E X T _ M S G M E R G E _ E X E C U T A B L E } - - q u i e t - - u p d a t e - - b a c k u p = n o n e - s $ { _ a b s F i l e } $ { _ a b s P o t F i l e }
2021-12-12 22:27:35 +00:00
$ { _ c o m p i l e C o m m a n d }
D E P E N D S $ { _ a b s P o t F i l e } $ { _ a b s F i l e }
)
2021-07-04 05:24:21 +00:00
ELSE ( CMAKE_BUILD_PO )
2021-12-12 22:27:35 +00:00
ADD_CUSTOM_COMMAND ( OUTPUT ${ _moFile }
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { _ l a n g }
$ { _ c o m p i l e C o m m a n d }
D E P E N D S $ { _ a b s F i l e }
)
2021-07-04 05:24:21 +00:00
ENDIF ( CMAKE_BUILD_PO )
2011-01-20 20:45:07 +00:00
2021-12-12 22:27:35 +00:00
IF ( APPLE )
target_sources ( PCSX2 PRIVATE ${ _moFile } )
2021-12-12 22:35:53 +00:00
set_source_files_properties ( ${ _moFile } PROPERTIES MACOSX_PACKAGE_LOCATION Resources/locale/ ${ _lang } )
2021-12-12 22:27:35 +00:00
source_group ( Resources/locale/ ${ __lang } FILES ${ _moFile } )
ELSEIF ( PACKAGE_MODE )
INSTALL ( FILES ${ _moFile } DESTINATION ${ CMAKE_INSTALL_DATADIR } /PCSX2/resources/locale/ ${ _lang } )
ELSE ( )
INSTALL ( FILES ${ _moFile } DESTINATION ${ CMAKE_SOURCE_DIR } /bin/resources/locale/ ${ _lang } )
ENDIF ( )
2011-01-20 20:45:07 +00:00
2021-12-12 22:27:35 +00:00
LIST ( APPEND _moFiles ${ _moFile } )
2011-01-20 20:45:07 +00:00
2021-12-12 22:27:35 +00:00
ENDFOREACH ( _currentPoFile )
2011-01-20 20:45:07 +00:00
2021-12-12 22:35:53 +00:00
IF ( NOT LINUX_PACKAGE AND NOT APPLE )
2021-12-12 22:38:02 +00:00
ADD_CUSTOM_TARGET ( translations_ ${ _potBasename } ALL DEPENDS ${ _moFiles } )
2021-12-12 22:35:53 +00:00
ENDIF ( NOT LINUX_PACKAGE AND NOT APPLE )
2011-01-20 20:45:07 +00:00
2021-12-12 22:42:04 +00:00
ENDFUNCTION ( GETTEXT_CREATE_TRANSLATIONS_PCSX2 )