summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/CMakeL10n.txt
blob: b666e209e85d8168c30c936f03fdd7d098eaaea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
##### prepare strings from data files ###########

message( STATUS "Prepare to extract strings from kstars data files..." )

## extract constellations
file( READ "${CMAKE_CURRENT_SOURCE_DIR}/data/cnames.dat" _cnames )
string( REGEX REPLACE " +(\n|\$)" "\\1" _cnames "${_cnames}" )
string( REGEX REPLACE
    "(^|\n)[0-9][^ ]* ([^\n]+)"
    "\\1i18n(\"Constellation name (optional)\", \"\\2\");"
    _cnames "${_cnames}" )
file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/data/cnames.dat.tde_l10n" "${_cnames}" )

## extract cities, regions and countries
file( READ "${CMAKE_CURRENT_SOURCE_DIR}/data/Cities.dat" _cities )
string( REGEX REPLACE "(^|\n)([^:]*): *([^:]*): *([^:]*):[^\n]*" "\\1\\2:\\3:\\4:" _cities "${_cities}" )
string( REGEX REPLACE " +:" ":" _cities "${_cities}" )
string( REGEX REPLACE
    "([^:]+):([^:]*):([^:]*):(\n|\$)"
    "i18n(\"City name (optional, probably does not need a translation)\", \"\\1\"):\\2:\\3:\\4"
    _cities "${_cities}" )
string( REGEX REPLACE
    "([^:]*):([^:]+):([^:]*):(\n|\$)"
    "\\1:i18n(\"Region/state name (optional, rarely needs a translation)\", \"\\2\"):\\3:\\4"
    _cities "${_cities}" )
string( REGEX REPLACE
    "([^:]*):([^:]*):([^:]+):(\n|\$)"
    "\\1:\\2:i18n(\"Country name (optional, but should be translated)\", \"\\3\"):\\4"
    _cities "${_cities}" )
string( REPLACE ":" ";" _cities "${_cities}" )
file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/data/Cities.dat.tde_l10n" "${_cities}" )

## extract image/info menu items
file( READ "${CMAKE_CURRENT_SOURCE_DIR}/data/image_url.dat" _image_url )
string( REGEX REPLACE
    "([^:\n]*):([^:\n]+):http[^\n]*\n"
    "i18n(\"Image/info menu item (should be translated)\", \"\\2\");\n"
    _image_url "${_image_url}" )
string( REGEX REPLACE "(^|\n)#" "\\1//" _image_url "${_image_url}" )
file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/data/image_url.dat.tde_l10n" "${_image_url}" )

file( READ "${CMAKE_CURRENT_SOURCE_DIR}/data/info_url.dat" _info_url )
string( REGEX REPLACE
    "([^:\n]*):([^:\n]+):http[^\n]*\n"
    "i18n(\"Image/info menu item (should be translated)\", \"\\2\");\n"
    _info_url "${_info_url}" )
string( REGEX REPLACE "(^|\n)#" "\\1//" _info_url "${_info_url}" )
file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/data/info_url.dat.tde_l10n" "${_info_url}" )

## star names : some might be different in other languages,
## or they might have to be adapted to non-Latin alphabets
file( GLOB_RECURSE _hip_files
    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/data/hip*.dat
)
list( SORT _hip_files )
unset( _hip_files_l10n )
foreach( _hip_file ${_hip_files} )
    # read file
    file( READ "${CMAKE_CURRENT_SOURCE_DIR}/${_hip_file}" _hip_data )
    string( REGEX REPLACE "[^\n]" "" _hip_len ${_hip_data} )
    string( LENGTH "+${_hip_len}" _hip_len )

    # process lines
    set( _hip_pos 0 )
    unset( _hip_l10n )
    while( _hip_pos LESS ${_hip_len} )
      # pick line
      string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _hip_line "${_hip_data}" )
      string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _hip_data "${_hip_data}" )
      math( EXPR _hip_pos "${_hip_pos}+1" )

      string( LENGTH "${_hip_line}" _hip_line_len )
      if( _hip_line_len LESS 72 OR "${_hip_line}" MATCHES "^#" )
        set( _hip_line "" )
      else( )
        string( SUBSTRING "${_hip_line}" 72 -1 _hip_line )
        string( REGEX MATCH "^([^:]+)" _hip_line "${_hip_line}" )
        string( STRIP "${_hip_line}" _hip_line )
        if( NOT "${_hip_line}" STREQUAL "" )
          set( _hip_line "i18n(\"star name\", \"${_hip_line}\");" )
        endif( )
      endif( )
      set( _hip_l10n "${_hip_l10n}${_hip_line}\n" )
    endwhile( )

    # write file
    file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/${_hip_file}.tde_l10n" "${_hip_l10n}" )
    list( APPEND _hip_files_l10n "${_hip_file}.tde_l10n" )
endforeach( )

## extract deep-sky object names
file( GLOB_RECURSE _ngcic_files
    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/data/ngcic*.dat
)
list( SORT _ngcic_files )
unset( _ngcic_files_l10n )
foreach( _ngcic_file ${_ngcic_files} )
    # read file
    file( READ "${CMAKE_CURRENT_SOURCE_DIR}/${_ngcic_file}" _ngcic_data )
    string( REGEX REPLACE "[^\n]" "" _ngcic_len ${_ngcic_data} )
    string( LENGTH "+${_ngcic_len}" _ngcic_len )

    # process lines
    set( _ngcic_pos 0 )
    unset( _ngcic_l10n )
    while( _ngcic_pos LESS ${_ngcic_len} )
      # pick line
      string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _ngcic_line "${_ngcic_data}" )
      string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _ngcic_data "${_ngcic_data}" )
      math( EXPR _ngcic_pos "${_ngcic_pos}+1" )

      string( LENGTH "${_ngcic_line}" _ngcic_line_len )
      if( _ngcic_line_len LESS 76 OR "${_ngcic_line}" MATCHES "^#" )
        set( _ngcic_line "" )
      else( )
        string( SUBSTRING "${_ngcic_line}" 76 -1 _ngcic_line )
        string( STRIP "${_ngcic_line}" _ngcic_line )
        if( NOT "${_ngcic_line}" STREQUAL "" )
          set( _ngcic_line "i18n(\"object name (optional)\", \"${_ngcic_line}\");" )
        endif( )
      endif( )
      set( _ngcic_l10n "${_ngcic_l10n}${_ngcic_line}\n" )
    endwhile( )

    # write file
    file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/${_ngcic_file}.tde_l10n" "${_ngcic_l10n}" )
    list( APPEND _ngcic_files_l10n "${_ngcic_file}.tde_l10n" )
endforeach( )

## extract strings from file containing advanced URLs:
file( READ "${CMAKE_CURRENT_SOURCE_DIR}/data/advinterface.dat" _kslabel )
string( REGEX REPLACE
    "\\[KSLABEL\\]([^\n]*)(\n|\$)"
    "i18n(\"Advanced URLs: description or category\", \"\\1\");\\2"
    _kslabel "${_kslabel}" )
file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/data/advinterface.dat.tde_l10n" "${_kslabel}" )


##### create translation templates ##############

tde_l10n_create_template(
    CATALOG "kstars"
    SOURCES
        "."
        "data/tips"
        "data/cnames.dat.tde_l10n"
        "data/Cities.dat.tde_l10n"
        "data/image_url.dat.tde_l10n"
        "data/info_url.dat.tde_l10n"
        ${_hip_files_l10n}
        ${_ngcic_files_l10n}
        "data/advinterface.dat.tde_l10n"
)