Warning, /sdk/cutehmi/qbs/modules/cutehmi/i18n/i18n.qbs is written in an unsupported language. File is not indexed.

0001 import qbs
0002 import qbs.File
0003 import qbs.FileInfo
0004 import qbs.TextFile
0005 
0006 /**
0007   This module generates 'cutehmi.i18n.pro' artifact, which then acts as an input for 'lupdate' program, which in turn produces
0008   translation files, which are compiled by 'lrelease' program into 'qm' files, which can be loaded by an application.
0009   */
0010 Module {
0011         additionalProductTypes: ["cutehmi.i18n"]
0012 
0013         /*
0014           Unfortunately you can not simply add empty files to the product, cause 'Qt.core' module has a rule, which calls 'lrelease' on
0015           every 'ts' file in the product and 'lrelease' triggers error if these files are empty. Additionaly 'lupdate' also triggers
0016           errors, when parsing 'pro' file. Instead this property can be used to create new translation file.
0017           */
0018         property stringList additionalTranslations: []
0019 
0020         property bool update: false
0021 
0022         property string lupdateProgram: "lupdate"
0023 
0024         property string lreleaseProgram: "lrelease"
0025 
0026         property bool lreleaseMultiplex: false
0027 
0028         Depends { name: "Qt.core" }
0029 
0030         Depends { name: "cutehmi.dirs" }
0031 
0032         FileTagger {
0033                 patterns: ["*.ts"]
0034                 fileTags: ["ts"]
0035         }
0036 
0037         FileTagger {
0038                 patterns: "*.js"
0039                 fileTags: ["js"]
0040         }
0041 
0042         FileTagger {
0043                 patterns: "*.qml"
0044                 fileTags: ["qml"]
0045         }
0046 
0047         Rule {
0048                 condition: update
0049                 multiplex: true
0050                 inputs: ["qml", "js", "hpp", "cpp", "ts"]
0051 
0052                 prepare: {
0053                         var proCmd = new JavaScriptCommand();
0054                         proCmd.description = 'generating ' + output.filePath
0055                         proCmd.highlight = 'codegen';
0056                         proCmd.sourceCode = function() {
0057                                 var f = new TextFile(output.filePath, TextFile.WriteOnly)
0058                                 try {
0059                                         f.writeLine("lupdate_only {")
0060                                         if (inputs["hpp"] !== undefined)
0061                                                 for (var i = 0; i < inputs["hpp"].length; i++)
0062                                                         f.writeLine("HEADERS += " + FileInfo.relativePath(product.sourceDirectory, inputs["hpp"][i].filePath))
0063                                         if (inputs["cpp"] !== undefined)
0064                                                 for (var i = 0; i < inputs["cpp"].length; i++)
0065                                                         f.writeLine("SOURCES += " + FileInfo.relativePath(product.sourceDirectory, inputs["cpp"][i].filePath))
0066                                         if (inputs["qml"] !== undefined)
0067                                                 for (var i = 0; i < inputs["qml"].length; i++)
0068                                                         f.writeLine("SOURCES += " + FileInfo.relativePath(product.sourceDirectory, inputs["qml"][i].filePath))
0069                                         if (inputs["js"] !== undefined)
0070                                                 for (var i = 0; i < inputs["js"].length; i++)
0071                                                         f.writeLine("SOURCES += " + FileInfo.relativePath(product.sourceDirectory, inputs["js"][i].filePath))
0072                                         f.writeLine("}")
0073 
0074                                         f.writeLine("")
0075                                         if (inputs["ts"] !== undefined)
0076                                                 for (var i = 0; i < inputs["ts"].length; i++)
0077                                                         f.writeLine("TRANSLATIONS += " + FileInfo.relativePath(product.sourceDirectory, inputs["ts"][i].filePath))
0078                                         for (var i = 0; i < product.cutehmi.i18n.additionalTranslations.length; i++) {
0079                                                 var targetDirectory = product.sourceDirectory + "/" + FileInfo.path(product.cutehmi.i18n.additionalTranslations[i])
0080                                                 if (!File.exists(targetDirectory))
0081                                                         console.error("Directory '" + targetDirectory + "' does not exists. Please create it.")
0082                                                 f.writeLine("TRANSLATIONS += " + product.cutehmi.i18n.additionalTranslations[i])
0083                                         }
0084                                 } finally {
0085                                         f.close()
0086                                 }
0087                         }
0088                         return [proCmd];
0089                 }
0090 
0091                 Artifact {
0092                         filePath: product.sourceDirectory + "/cutehmi.i18n.pro"
0093                         fileTags: ["cutehmi.i18n.pro"]
0094                 }
0095         }
0096 
0097         Rule {
0098                 multiplex: true
0099                 inputs: ["cutehmi.i18n.pro"]
0100 
0101                 prepare: {
0102                         var lupdateProgram = product.cutehmi.i18n.lupdateProgram
0103                         var cmd = new Command(product.Qt.core.binPath + '/' + lupdateProgram, ["-verbose", inputs["cutehmi.i18n.pro"][0].filePath])
0104                         cmd.description = "invoking '" + lupdateProgram + "' program"
0105                         cmd.highlight = 'filegen'
0106                         return cmd
0107                 }
0108 
0109                 outputFileTags: ["cutehmi.i18n"]
0110         }
0111 }
0112 
0113 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
0114 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
0115 //(c)C: This file is a part of CuteHMI.
0116 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
0117 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
0118 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI.  If not, see <https://www.gnu.org/licenses/>.
0119 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
0120 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
0121 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
0122 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.