2018-05-03 16:18:15 -05:00
add_subdirectory ( glossary )
2015-12-07 11:17:08 -06:00
2018-10-17 00:33:38 -05:00
# Set of available languages:
2022-11-07 19:13:52 -06:00
set ( ALL_LINGUAS ar as az bg brx ca cs da de doi el en_AU en_GB en_NZ es es_NI et eu fa fi fr gu he hi hr hu id it ja kn ko kok kok@latin ks lt lv mai mk mni mni@bengali mr nb ne nl pl pt pt_BR ro rw sk sr sv ru ta te tr uk ur vi zh_CN zh_TW )
2021-03-23 09:25:08 -05:00
# LINGUAS is used to create localized destkop and appdata files
string ( REPLACE ";" " " LINGUAS "${ALL_LINGUAS}" )
file ( WRITE ${ CMAKE_CURRENT_SOURCE_DIR } /LINGUAS "${LINGUAS}" )
2018-02-27 08:45:38 -06:00
2018-05-03 16:18:15 -05:00
set ( CATALOGS "" )
2021-03-23 09:25:08 -05:00
set ( po_SOURCES "" )
2016-01-13 10:45:29 -06:00
2021-03-23 09:25:08 -05:00
foreach ( lingua ${ ALL_LINGUAS } )
list ( APPEND po_SOURCES ${ lingua } .po )
2017-02-01 21:48:46 -06:00
2021-03-23 09:25:08 -05:00
set ( _LOCALE_DIR ${ DATADIR_BUILD } /locale/ ${ lingua } /LC_MESSAGES )
2021-03-23 10:33:56 -05:00
file ( MAKE_DIRECTORY "${_LOCALE_DIR}" ) # Unix Makefiles won't do this automatically, ninja does
2021-03-23 09:25:08 -05:00
set ( _MO_FILE ${ _LOCALE_DIR } /gnucash.mo )
list ( APPEND CATALOGS ${ _MO_FILE } )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
add_custom_command (
2021-03-23 09:25:08 -05:00
O U T P U T $ { _ M O _ F I L E }
2023-02-26 10:26:48 -06: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 }
2021-03-23 09:25:08 -05:00
- o $ { _ M O _ F I L E } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { l i n g u a } . p o
2019-05-27 07:47:35 -05:00
D E P E N D S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { l i n g u a } . p o
2015-12-07 11:17:08 -06:00
)
2021-03-23 09:25:08 -05:00
install ( FILES ${ _MO_FILE } DESTINATION ${ CMAKE_INSTALL_DATADIR } /locale/ ${ lingua } /LC_MESSAGES )
endforeach ( lingua )
2015-12-07 11:17:08 -06:00
2021-03-23 09:25:08 -05:00
add_custom_target ( po-gmo ALL DEPENDS ${ CATALOGS } )
2015-12-07 11:17:08 -06:00
2021-06-30 10:34:54 -05:00
set_local_dist ( po_DIST_local ${ po_SOURCES } CMakeLists.txt
2022-06-20 14:51:05 -05:00
P O T F I L E S . i n P O T F I L E S . i g n o r e P O T F I L E S . s k i p R E A D M E g n u c a s h - p o t . c m a k e )
2021-03-23 09:25:08 -05:00
set ( po_DIST ${ po_DIST_local } ${ po_glossary_DIST } PARENT_SCOPE )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
function ( read_file_removing_comments OUTPUT PATH )
set ( RESULT "" )
file ( STRINGS "${PATH}" LINES_IN )
foreach ( line ${ LINES_IN } )
string ( REGEX REPLACE "#.*" "" line2 ${ line } )
list ( APPEND RESULT ${ line2 } )
endforeach ( )
set ( ${ OUTPUT } ${ RESULT } PARENT_SCOPE )
endfunction ( )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
function ( make_gnucash_potfiles )
2017-02-01 21:48:46 -06:00
# Create a list of candidate translation files
2018-02-28 06:40:15 -06:00
file ( GLOB_RECURSE FILES_IN RELATIVE ${ CMAKE_SOURCE_DIR }
$ { C M A K E _ S O U R C E _ D I R } / * . c $ { C M A K E _ S O U R C E _ D I R } / * . c p p
$ { C M A K E _ S O U R C E _ D I R } / * . g l a d e $ { C M A K E _ S O U R C E _ D I R } / * . d e s k t o p . i n . i n
2019-08-26 11:57:45 -05:00
$ { C M A K E _ S O U R C E _ D I R } / * . g s c h e m a . x m l . i n $ { C M A K E _ S O U R C E _ D I R } / * . a p p d a t a . x m l . i n . i n
2018-02-28 06:40:15 -06:00
$ { C M A K E _ S O U R C E _ D I R } / * . k e y s . i n $ { C M A K E _ S O U R C E _ D I R } / * . s c m
2020-02-29 09:16:05 -06:00
$ { C M A K E _ S O U R C E _ D I R } / * . p y $ { C M A K E _ S O U R C E _ D I R } / * / q o f b o o k s l o t s . h
2019-12-29 15:25:14 -06:00
$ { C M A K E _ S O U R C E _ D I R } / * / g n c - c o m m o d i t y . h
2022-10-30 08:22:28 -05:00
$ { C M A K E _ S O U R C E _ D I R } / * . u i
2018-02-28 06:40:15 -06:00
)
2017-02-01 21:48:46 -06:00
2018-02-28 06:40:15 -06:00
# Only consider files in a selection of the source directories and
# additionally check against list of ignore patterns
set ( GOOD_FILES "" )
foreach ( path ${ FILES_IN } )
if ( ${ path } MATCHES "^(bindings/|borrowed/|common/|doc/|libgnucash/|gnucash/)"
A N D
2020-05-24 15:45:32 -05:00
N O T $ { p a t h } M A T C H E S " g w - | m o c k s | t e s t | e x p e r i m e n t a l | p y t h o n - b i n d i n g s | s w i g - . * \ \ . c "
2018-11-04 06:07:36 -06:00
# Skip POSIX style hidden files even if they have the proper extension
# These are typically temporary files from editors like emacs
A N D
N O T $ { p a t h } M A T C H E S " / [ . ] [ ^ / ] * $ " )
2018-02-28 06:40:15 -06:00
list ( APPEND GOOD_FILES ${ path } )
2020-02-06 09:16:31 -06:00
endif ( )
2018-02-28 06:40:15 -06:00
endforeach ( path )
# Remove the paths that we have marked as explicitly skipped
2018-05-03 16:18:15 -05:00
read_file_removing_comments ( SKIP_LINES POTFILES.skip )
2018-02-28 06:40:15 -06:00
foreach ( path ${ SKIP_LINES } )
list ( REMOVE_ITEM GOOD_FILES ${ path } )
endforeach ( )
2017-02-01 21:48:46 -06:00
2022-06-20 14:51:05 -05:00
# Remove the paths that we have marked as explicitly ignore
read_file_removing_comments ( SKIP_LINES POTFILES.ignore )
foreach ( path ${ SKIP_LINES } )
list ( REMOVE_ITEM GOOD_FILES ${ path } )
endforeach ( )
2017-07-04 20:36:35 -05:00
2018-01-26 09:06:29 -06:00
# CMake sorting is different from UNIX sorting. Use perl to
# sort POTFILES.in universally. This may no longer be needed
# now we have dropped autotools support.
2018-05-03 16:18:15 -05:00
string ( REPLACE ";" "\n" SORT_IN "${GOOD_FILES}" )
set ( SORT_IN "${SORT_IN}\n" )
file ( WRITE ${ CMAKE_CURRENT_BINARY_DIR } /POTFILES.in.in "${SORT_IN}" )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
execute_process ( COMMAND "${PERL_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/util/elegant-sort.pl"
2017-02-01 21:48:46 -06:00
I N P U T _ F I L E $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / P O T F I L E S . i n . i n
O U T P U T _ V A R I A B L E P O T F I L E S _ I N
)
2018-05-03 16:18:15 -05:00
string ( REPLACE "\n" ";" POTFILES "${POTFILES_IN}" )
2017-02-01 21:48:46 -06:00
# Write out the final list.
# intltool-update insists that this file be in the source directory. :-(
2018-05-03 16:18:15 -05:00
set ( POTFILES_IN_PATH ${ CMAKE_CURRENT_BINARY_DIR } /POTFILES.in )
file ( WRITE ${ POTFILES_IN_PATH } " # This is a list of files which contain translatable strings.
2018-01-26 09:06:29 -06:00
# This file was autogenerated by cmake.
2017-02-01 21:48:46 -06:00
" )
2018-01-29 14:51:38 -06:00
set ( POTFILE_DEPS "" )
2018-05-03 16:18:15 -05:00
foreach ( path ${ POTFILES } )
2018-01-29 14:51:38 -06:00
list ( APPEND POTFILE_DEPS ${ CMAKE_SOURCE_DIR } / ${ path } )
2018-05-03 16:18:15 -05:00
file ( APPEND ${ POTFILES_IN_PATH } "${path}\n" )
endforeach ( )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
configure_file ( ${ POTFILES_IN_PATH } ${ CMAKE_CURRENT_SOURCE_DIR } /POTFILES.in NEWLINE_STYLE LF )
2018-01-29 14:51:38 -06:00
set ( gnucash_pot_depends ${ POTFILE_DEPS } CACHE INTERNAL "List of files with translatable strings. If any of these change, gnucash.pot should be regenerated" )
2018-05-03 16:18:15 -05:00
endfunction ( )
2017-02-01 21:48:46 -06:00
2020-02-07 14:56:21 -06:00
if ( BUILD_GNUCASH_POT )
2017-02-01 21:48:46 -06:00
2018-05-03 16:18:15 -05:00
make_gnucash_potfiles ( )
2017-02-01 21:48:46 -06:00
find_program ( XGETTEXT xgettext )
2018-05-03 16:18:15 -05:00
if ( ${ XGETTEXT } STREQUAL "XGETTEXT-NOTFOUND" )
message ( FATAL_ERROR "Can't find the 'xgettext' program." )
2020-02-06 09:16:31 -06:00
endif ( )
2017-02-01 21:48:46 -06:00
2018-01-29 05:19:47 -06:00
add_custom_command ( OUTPUT gnucash.pot
2018-01-27 12:00:30 -06:00
C O M M A N D $ { C M A K E _ C O M M A N D }
2018-02-27 08:45:38 -06:00
- D T O P _ S R C _ D I R = $ { C M A K E _ S O U R C E _ D I R }
2018-01-27 12:00:30 -06:00
- D P O _ S R C _ D I R = $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
- D P O _ B I N _ D I R = $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
2020-01-17 09:28:56 -06:00
- D P R O J E C T _ N A M E = $ { P R O J E C T _ N A M E }
2018-03-01 11:31:49 -06:00
- D P A C K A G E _ N A M E = $ { P A C K A G E _ N A M E }
2020-01-17 09:28:56 -06:00
- D P R O J E C T _ V E R S I O N = $ { P R O J E C T _ V E R S I O N }
2018-01-27 12:00:30 -06:00
- D X G E T T E X T = $ { X G E T T E X T }
- P $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / g n u c a s h - p o t . c m a k e
2018-01-29 14:51:38 -06:00
D E P E N D S $ { g n u c a s h _ p o t _ d e p e n d s }
2018-01-27 12:00:30 -06:00
W O R K I N G _ 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 }
)
2018-01-29 14:51:38 -06:00
add_custom_target ( pot DEPENDS gnucash.pot )
2018-05-03 16:18:15 -05:00
endif ( )
2018-01-31 09:16:59 -06:00
dist_add_generated ( ${ BUILDING_FROM_VCS } gnucash.pot )
2022-10-08 23:47:12 -05:00
if ( BUILD_GNUCASH_POT )
add_dependencies ( dist-po-gnucash-pot pot )
endif ( )