File: generate_styles_string.sh

package info (click to toggle)
darktable 5.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 62,864 kB
  • sloc: ansic: 361,898; cpp: 102,446; xml: 19,813; lisp: 14,539; sh: 3,771; javascript: 3,264; perl: 1,925; python: 1,485; ruby: 975; makefile: 543; asm: 46; sql: 38; awk: 21
file content (53 lines) | stat: -rwxr-xr-x 1,366 bytes parent folder | download
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
#!/usr/bin/env bash

STYLE_DIR=$1
OUT=$2

# Get the l10n strings from styles. Such strings are prefixed by _l10n_
function get-l10n()
{
    #  1. Get the "name" node value using xsltproc
    #
    #  2. Cut substrings separated with | and keep only those
    #     with _l10n_ prefix.
    #
    #  3. Remove all _l10n_ sentinel with sed
    #
    #  4. Finaly generates into the while loop the pseudo C code for
    #     the strings to be translated.

    xsltproc "$SCR" "$1" |
        tr '|' '\n' | grep _l10n_ | sed 's/_l10n_//g' |
        while read line; do
            echo "_(\"$line\")"
        done
}

SCR=$(mktemp)

echo '<?xml version="1.0"?>
         <xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:output indent="yes" omit-xml-declaration="yes"/>
            <xsl:template match="info">
               <xsl:value-of select="name"/>
               <xsl:text>&#10;</xsl:text>
               <xsl:value-of select="description"/>
            </xsl:template>
            <xsl:template match="style"/>
         </xsl:stylesheet>' > $SCR

export IFS=$'\n'

{
    echo "// Not to be compiled, generated for translation only"
    echo

    #  Ensure that we remove the duplicate strings

    ls $STYLE_DIR/*.dtstyle | while read file; do
        get-l10n $file
    done | sort | uniq
} > $OUT

rm $SCR