pax_global_header00006660000000000000000000000064141423674100014514gustar00rootroot0000000000000052 comment=c913e2d7f9ea6ee394e3640dfca807d802806607 deepin-gettext-tools-1.0.10/000077500000000000000000000000001414236741000156575ustar00rootroot00000000000000deepin-gettext-tools-1.0.10/.gitignore000066400000000000000000000001761414236741000176530ustar00rootroot00000000000000*.pyc nohup.out .#* *~ build dist dtk.egg-info *.po~ *.swp *.user.* *.old *.mo Makefile *.cache *.o build lib mkspecs *.user deepin-gettext-tools-1.0.10/CHANGELOG.md000066400000000000000000000000741414236741000174710ustar00rootroot00000000000000 ## [1.0.8] 2018-03-09 * fix ts2policy KeyError exception deepin-gettext-tools-1.0.10/LICENSE000066400000000000000000000432541414236741000166740ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. deepin-gettext-tools-1.0.10/Makefile000066400000000000000000000012261414236741000173200ustar00rootroot00000000000000PREFIX = /usr build: install: mkdir -pv ${DESTDIR}${PREFIX}/lib/deepin-gettext-tools mkdir -pv ${DESTDIR}${PREFIX}/bin install -m755 src/generate_mo.py ${DESTDIR}${PREFIX}/lib/deepin-gettext-tools/ install -m755 src/update_pot.py ${DESTDIR}${PREFIX}/lib/deepin-gettext-tools/ ln -sf ${PREFIX}/lib/deepin-gettext-tools/generate_mo.py ${DESTDIR}${PREFIX}/bin/deepin-generate-mo ln -sf ${PREFIX}/lib/deepin-gettext-tools/update_pot.py ${DESTDIR}${PREFIX}/bin/deepin-update-pot install -m755 src/desktop_ts_convert.pl ${DESTDIR}${PREFIX}/bin/deepin-desktop-ts-convert install -m755 src/policy_ts_convert.py ${DESTDIR}${PREFIX}/bin/deepin-policy-ts-convert deepin-gettext-tools-1.0.10/README.md000066400000000000000000000046601414236741000171440ustar00rootroot00000000000000# deepin-desktop-ts-convert 处理 desktop 文件翻译的便捷工具 有关如何使用可参考项目 [deepin-feedback](https://github.com/linuxdeepin/deepin-feedback) ## 子命令介绍 有3个子命令: init, desktop2ts, ts2desktop。如果不带任何参数运行本命令则显示帮助信息。 ### 子命令 init ``` deepin-desktop-ts-convert init $desktopFile $outputTsDir ``` 用于在项目中开始处理一个desktop文件的翻译问题,将翻译源写入`$outputTsDir/desktop.ts`文件,和已有的翻译成果写入各个 `$outputTsDir/desktop_.ts` 文件中(`` 是指某种具体的语言代码)。 ### 子命令 desktop2ts ``` deepin-desktop-ts-convert desktop2ts $desktopFile $outputTsDir ``` 子命令 desktop2ts 与子命令 init 传参是一样的,用于更新翻译源文件,将翻译源写入`$outputTsDir/desktop.ts`文件。应该在 desktop 文件中的可以本地化的字段的值被更新后使用,相关字段有 Name,Comment,GenericName,Keywords。 ### 子命令 ts2desktop ``` deepin-desktop-ts-convert ts2desktop $desktopFile $tsDir $outputDesktopFile ``` 用于输出带有翻译结果的 desktop 文件,参数 `$desktopFile` 是模板文件,参数 `$tsDir` 是放置相关 ts 文件的文件夹,将集合了各种语言翻译成果的desktop写入`$outputDesktopFile`文件。推荐在构建软件包过程中使用。 ## 推荐使用流程 ### 开始一个新项目 1. 如果 desktop 文件中已有翻译,使用 init 子命令,否则使用 deskotp2ts 子命令; 2. 将 desktop 文件的后缀改为 `.desktop.in` 作为一个模板,去除里面的翻译; 3. 在 Makefile 里面写一个构建项 ts,当 desktop.in 文件中相关字段的值更新后,执行 make ts; 4. 在 .tx/config 写好资源配置; 5. 在 Makefile 中的 build 项中增加使用 ts2desktop 子命令; 6. 用 ci 的 [sync-transifex](https://ci.deepin.io/view/tools/job/sync-transifex/) 上传翻译源文件; 7. 如果已有一些翻译成果,找翻译管理员,`git clone` 你的项目,然后执行 `tx push -t` 命令上传翻译,tx 命令由软件包 transifex-client 提供; ### 更新翻译成果 1. 用 ci 的 sync-transifex 拉取翻译结果 ### 更新模板文件 desktop.in,修改了本地化相关字段 1. 使用 desktop2ts 子命令; 2. 将模板文件 desktop.in 和它的翻译源文件 desktop.ts 在 git 中提交; 3. 用 ci 的 sync-transifex 上传翻译源文件; deepin-gettext-tools-1.0.10/debian/000077500000000000000000000000001414236741000171015ustar00rootroot00000000000000deepin-gettext-tools-1.0.10/debian/changelog000066400000000000000000000014061414236741000207540ustar00rootroot00000000000000deepin-gettext-tools (1.0.6-1) unstable; urgency=medium * New upstream release. -- Boyuan Yang <073plan@gmail.com> Mon, 28 Aug 2017 15:11:02 +0800 deepin-gettext-tools (1.0.3) unstable; urgency=low * Autobuild Tag 1.0.3 -- TagBuilder Mon, 23 May 2016 12:49:59 +0000 deepin-gettext-tools (1.0.1-1) stable; urgency=low * Autobuild Tag 1.0.1 -- TagBuilder Fri, 14 Aug 2015 09:53:56 +0000 deepin-gettext-tools (1.0.0-1) stable; urgency=low * Autobuild Tag 1.0.0-1 -- TagBuilder Wed, 01 Jul 2015 08:11:33 +0000 deepin-gettext-tools (0.0.0) unstable; urgency=low * Unstable release. -- 宋文武 Thu, 18 Sep 2014 11:28:07 +0800 deepin-gettext-tools-1.0.10/debian/compat000066400000000000000000000000021414236741000202770ustar00rootroot000000000000009 deepin-gettext-tools-1.0.10/debian/control000066400000000000000000000012201414236741000204770ustar00rootroot00000000000000Source: deepin-gettext-tools Section: devel Priority: optional Build-Depends: debhelper (>= 9), Standards-Version: 4.0.0 Maintainer: Deepin Sysdev Homepage: https://github.com/linuxdeepin/deepin-gettext-tools Package: deepin-gettext-tools Architecture: all Depends: gettext, libconfig-tiny-perl, libxml-libxml-perl, perl, python, python3, ${misc:Depends}, Description: Deepin Internationalization utilities This package provides various tools used by Deepin software to extract translatable string and manage i18n works as a supplement to regular gettext tools. . This package is part of DDE (Deepin Desktop Environment). deepin-gettext-tools-1.0.10/debian/copyright000066400000000000000000000016631414236741000210420ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: deepin-gettext-tools Files: * Copyright: 2010-2021 Deepin Technology Co., Ltd. License: GPL-2+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This package 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 General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . On Debian systems, the complete text of the GNU General Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". deepin-gettext-tools-1.0.10/debian/deepin-desktop-ts-convert.1000066400000000000000000000053131414236741000242020ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" (C) Copyright 2017 Boyuan Yang <073plan@gmail.com>, .\" .TH "DEEPIN-DESKTOP-TS-CONVERT" "1" "2017-08-11" "Deepin Gettext Tools" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME deepin-desktop-ts-convert \- convert between .desktop file and .ts file to ease translation .SH SYNOPSIS .B deepin-desktop-ts-convert init \fIdesktopFile outputTsDir\fR .br .B deepin-desktop-ts-convert desktop2ts \fIdesktopFile outputTsDir\fR .br .B deepin-desktop-ts-convert ts2desktop \fIdesktopFile tsDir outputDesktopFile\fR .SH DESCRIPTION This manual page documents briefly the .B deepin-desktop-ts-convert command as provided by .B deepin-gettext-tools package. .PP \fBdeepin-desktop-ts-convert\fP is a utility that helps developers convert translatable strings in desktop files into ts files to ease translation work. Translated strings in ts files can be merged back to original desktop file too with the help of this utility. .PP Such workflow is adopted by most Deepin software. .SH USAGE .PP To initialise conversion, use \fIdeepin-desktop-ts-convert init\fR subcommand. In which case source ts file will be put into \fIoutputTsDir/desktop.ts\fR and translation ts files should be named as \fIoutputTsDir/desktop_\.ts\fR. .sp .if n \{\ .RS 4 .\} .nf deepin-desktop-ts-convert init desktopFile outputTsDir .fi .if n \{\ .RE .\} .PP To update ts files from a new version of desktop file, use \fIdeepin-desktop-ts-convert desktop2ts\fR subcommand. The updated ts file given as outputTsDir/desktop.ts file. .sp .if n \{\ .RS 4 .\} .nf deepin-desktop-ts-convert desktop2ts desktopFile outputTsDir .fi .if n \{\ .RE .\} .PP To generate translated desktop files, use \fIdeepin-desktop-ts-convert ts2desktop\fR subcommand. .sp .if n \{\ .RS 4 .\} .nf deepin-desktop-ts-convert ts2desktop desktopFile tsDir outputDesktopFile .fi .if n \{\ .RE .\} .SH SEE ALSO .PP .BR deepin-update-pot (1), .BR deepin-generate-mo (1), .BR deepin-policy-ts-convert (1). .PP The programs are further documented in the .IR README.md as provided with this debian package under .IR /usr/share/doc/deepin-gettext-tools/ directory. .SH AUTHOR .PP .B deepin-gettext-tools is written by Deepin Technology Co., Ltd. .PP This manual page was written by .MT 073plan@\:gmail.com Boyuan Yang .ME for the Debian Project (but may be used by others). deepin-gettext-tools-1.0.10/debian/deepin-generate-mo.1000066400000000000000000000036561414236741000226420ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" (C) Copyright 2017 Boyuan Yang <073plan@gmail.com>, .\" .TH "DEEPIN-GENERATE-MO" "1" "2017-08-11" "Deepin Gettext Tools" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME deepin-generate-mo \- generate mo file from po file using deepin ini config file .SH SYNOPSIS .B deepin-generate-mo .RI [ \-h\ \-\-copy ] " inifile" .SH DESCRIPTION This manual page documents briefly the .B deepin-generate-mo command as provided by .B deepin-gettext-tools package. .PP \fBdeepin-generate-mo\fP is a utility that generate gettext MO files from gettext PO files using instructions from certain ini config file. .PP Such workflow is adopted by most Deepin software. .SH OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For latest descriptions as provided by the tool, invoke the tool with \fI\-h\fR option. .TP .B \-h, \-\-help Show help messages and exit. .TP .B \-\-copy Also execute commands similar to "sudo cp *.mo /usr/share/locale". .SH SEE ALSO .PP .BR deepin-update-pot (1), .BR deepin-desktop-ts-convert (1), .BR deepin-policy-ts-convert (1). .PP The programs are further documented in the .IR README.md as provided with this debian package under .IR /usr/share/doc/deepin-gettext-tools/ directory. .SH AUTHOR .PP .B deepin-gettext-tools is written by Deepin Technology Co., Ltd. .PP This manual page was written by .MT 073plan@\:gmail.com Boyuan Yang .ME for the Debian Project (but may be used by others). deepin-gettext-tools-1.0.10/debian/deepin-gettext-tools.examples000066400000000000000000000000271414236741000247240ustar00rootroot00000000000000src/example_config.ini deepin-gettext-tools-1.0.10/debian/deepin-policy-ts-convert.1000066400000000000000000000037061414236741000240340ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" (C) Copyright 2017 Boyuan Yang <073plan@gmail.com>, .\" .TH "DEEPIN-POLICY-TS-CONVERT" "1" "2017-08-11" "Deepin Gettext Tools" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME deepin-policy-ts-convert \- convert between policykit XML file and ts file to ease translation .SH SYNOPSIS .B deepin-policy-ts-convert init \fIpolicyFile outputTsDir\fR .br .B deepin-policy-ts-convert policy2ts \fIpolicyFile outputTsDir\fR .br .B deepin-policy-ts-convert ts2policy \fIpolicyFile tsDir outputPolicyFile\fR .SH DESCRIPTION This manual page documents briefly the .B deepin-policy-ts-convert command as provided by .B deepin-gettext-tools package. .PP \fBdeepin-policy-ts-convert\fP is a utility that helps developers convert translatable strings in PolicyKit XML files into ts files to ease translation work. Translated ts files can be merged back to original file too with the help of this utility. .PP Such workflow is adopted by most Deepin software. .SH USAGE Using this tool is similar to using \fBdeepin-desktop-ts-convert\fR(1) as shown in the SYNOPSIS section. .SH SEE ALSO .PP .BR deepin-update-pot (1), .BR deepin-generate-mo (1), .BR deepin-desktop-ts-convert (1), .PP The programs are further documented in the .IR README.md as provided with this debian package under .IR /usr/share/doc/deepin-gettext-tools/ directory. .SH AUTHOR .PP .B deepin-gettext-tools is written by Deepin Technology Co., Ltd. .PP This manual page was written by .MT 073plan@\:gmail.com Boyuan Yang .ME for the Debian Project (but may be used by others). deepin-gettext-tools-1.0.10/debian/deepin-update-pot.1000066400000000000000000000035211414236741000225100ustar00rootroot00000000000000.\" Hey, EMACS: -*- nroff -*- .\" (C) Copyright 2017 Boyuan Yang <073plan@gmail.com>, .\" .TH "DEEPIN-UPDATE-POT" "1" "2017-08-11" "Deepin Gettext Tools" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME deepin-update-pot \- generate pot file according to given ini config file .SH SYNOPSIS .B deepin-update-pot .RI [ \-h ] " inifile" .SH DESCRIPTION This manual page documents briefly the .B deepin-update-pot command as provided by .B deepin-gettext-tools package. .PP \fBdeepin-update-pot\fP is a utility that generate gettext POT template file from source code files using instructions from certain ini config file. .PP Such workflow is adopted by most Deepin software. .SH OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For latest descriptions as provided by the tool, invoke the tool with \fI\-h\fR option. .TP .B \-h, \-\-help Show help messages and exit. .SH SEE ALSO .PP .BR deepin-generate-mo (1), .BR deepin-desktop-ts-convert (1), .BR deepin-policy-ts-convert (1). .PP The programs are further documented in the .IR README.md as provided with this debian package under .IR /usr/share/doc/deepin-gettext-tools/ directory. .SH AUTHOR .PP .B deepin-gettext-tools is written by Deepin Technology Co., Ltd. .PP This manual page was written by .MT 073plan@\:gmail.com Boyuan Yang .ME for the Debian Project (but may be used by others). deepin-gettext-tools-1.0.10/debian/docs000066400000000000000000000000121414236741000177450ustar00rootroot00000000000000README.md deepin-gettext-tools-1.0.10/debian/manpages000066400000000000000000000001741414236741000206210ustar00rootroot00000000000000debian/deepin-generate-mo.1 debian/deepin-update-pot.1 debian/deepin-desktop-ts-convert.1 debian/deepin-policy-ts-convert.1 deepin-gettext-tools-1.0.10/debian/rules000077500000000000000000000000361414236741000201600ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ deepin-gettext-tools-1.0.10/debian/source/000077500000000000000000000000001414236741000204015ustar00rootroot00000000000000deepin-gettext-tools-1.0.10/debian/source/format000066400000000000000000000000141414236741000216070ustar00rootroot000000000000003.0 (quilt) deepin-gettext-tools-1.0.10/debian/watch000066400000000000000000000003151414236741000201310ustar00rootroot00000000000000version=4 opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%deepin-gettext-tools-$1.tar.gz%" \ https://github.com/linuxdeepin/deepin-gettext-tools/tags \ (?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian uupdate deepin-gettext-tools-1.0.10/rpm/000077500000000000000000000000001414236741000164555ustar00rootroot00000000000000deepin-gettext-tools-1.0.10/rpm/deepin-gettext-tools.spec000066400000000000000000000036211414236741000234170ustar00rootroot00000000000000Name: deepin-gettext-tools Version: 1.0.9 Release: 1 Summary: Deepin Gettext Tools License: GPLv3 URL: https://github.com/linuxdeepin/deepin-gettext-tools Source0: %{name}-%{version}.orig.tar.gz BuildArch: noarch BuildRequires: perl-XML-LibXML BuildRequires: python3-devel BuildRequires: perl(Config::Tiny) Requires: gettext Requires: qt5-linguist Requires: perl(Config::Tiny) Requires: perl(Exporter::Tiny) Requires: perl(XML::LibXML) Requires: perl(XML::LibXML::PrettyPrint) %description The tools of gettext function wrapper. desktop-ts-convert - handling desktop file translations. policy-ts-convert - convert PolicyKit Policy file to the ts file. update-pot - scan msgid and generate pot file according to the ini file. generate-mo - scan po files and generate mo files according to the ini file. %prep %setup -q # fix shebang find -iname "*.py" | xargs sed -i '1s|.*|#!%{__python3}|' sed -i '1s|.*|#!%{__perl}|' src/desktop_ts_convert.pl sed -i 's|sudo cp|cp|' src/generate_mo.py sed -i 's|lconvert|lconvert-qt5|; s|deepin-lupdate|lupdate-qt5|' src/update_pot.py %build %install install -d %{buildroot}%{_bindir} install -m755 src/desktop_ts_convert.pl %{buildroot}%{_bindir}/deepin-desktop-ts-convert install -m755 src/policy_ts_convert.py %{buildroot}%{_bindir}/deepin-policy-ts-convert install -m755 src/generate_mo.py %{buildroot}%{_bindir}/deepin-generate-mo install -m755 src/update_pot.py %{buildroot}%{_bindir}/deepin-update-pot %check /bin/perl src/desktop_ts_convert.pl --help /bin/python3 src/generate_mo.py --help /bin/python3 src/update_pot.py --help %files %doc README.md %license LICENSE %{_bindir}/deepin-desktop-ts-convert %{_bindir}/deepin-policy-ts-convert %{_bindir}/deepin-update-pot %{_bindir}/deepin-generate-mo %changelog * Thu Mar 23 2021 uoser - 1.0.9-1 - Update to 1.0.9 deepin-gettext-tools-1.0.10/src/000077500000000000000000000000001414236741000164465ustar00rootroot00000000000000deepin-gettext-tools-1.0.10/src/desktop_ts_convert.pl000066400000000000000000000253301414236741000227250ustar00rootroot00000000000000#!/usr/bin/env perl # # The desktop-ts-convert tool # # Copyright (C) 2017 Deepin.Inc # # desktop-ts-convert is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 3 published by the Free Software Foundation. # use warnings; use strict; use 5.018; use XML::LibXML; use Config::Tiny; use File::Basename qw(basename); use File::Path qw(make_path); my @localeKeys = qw(Name GenericName Comment Keywords); MAIN: { my $cmd = shift @ARGV // ''; if ($cmd eq 'init') { my ($desktopFile, $outputTsDir) = @ARGV; Init($desktopFile, $outputTsDir); } elsif ($cmd eq 'desktop2ts') { my ($desktopFile, $outputTsDir) = @ARGV; Desktop2TS($desktopFile, $outputTsDir); } elsif ( $cmd eq 'ts2desktop' ) { my ($desktopFile, $tsDir, $outputDesktopFile) = @ARGV; TS2Desktop($desktopFile, $tsDir, $outputDesktopFile); } else { printHelp(); } exit; } sub printHelp { my $bin = basename($0); print " Usage: init: $bin init \$desktopFile \$outputTsDir output source \$outputTsDir/desktop.ts and translation \$outputTsDir/desktop_.ts desktop -> ts: $bin desktop2ts \$desktopFile \$outputTsDir output source \$outputTsDir/desktop.ts ts -> desktop: $bin ts2desktop \$desktopFile \$tsDir \$outputDesktopFile document https://github.com/linuxdeepin/deepin-gettext-tools/blob/master/README.md " } sub Desktop2TS { my ($file, $outputTsDir) = @_; my $contextName = 'desktop'; my $desktopCfg = Config::Tiny->read($file, 'utf8'); my $dom = createDocument(); my $root = $dom->documentElement; my $context = getEmptyContext($dom, $contextName); my @msgs = createDesktopTsMessages($dom, $desktopCfg); $context->appendChild($_) for @msgs; # source make_path($outputTsDir); my $outputTsFile = "$outputTsDir/desktop.ts"; say "output ts file: ", $outputTsFile; saveDocument($dom, $outputTsFile, 1); } sub Init { my ($file, $outputTsDir) = @_; my $contextName = 'desktop'; my $desktopCfg = Config::Tiny->read($file, 'utf8'); my $dom = createDocument(); my $root = $dom->documentElement; my $context = getEmptyContext($dom, $contextName); my @msgs = createDesktopTsMessages($dom, $desktopCfg); $context->appendChild($_) for @msgs; # source make_path($outputTsDir); saveDocument($dom, "$outputTsDir/desktop.ts", 1); # translations my @langs = getDesktopLangs($desktopCfg); for my $lang ( @langs ) { my $langDom = createDocument($lang); my $langRoot = $langDom->documentElement; my $langContext = getEmptyContext($langDom, $contextName); ## fill translation my $sourceContextCopy = $context->cloneNode(1); ### $sourceContextCopy my @msgs = $sourceContextCopy->findnodes('./message'); ### @msgs for my $msg (@msgs) { ### $msg my $translation = ($msg->findnodes('./translation[1]'))[0]; die "not found translation" unless $translation; ### $translation my @locations = $msg->findnodes('./location'); die "not found any location" unless @locations; for my $location (@locations) { my ($section, $key) = getSectionKeyWithLocationLang($location, $lang); my $value = $desktopCfg->{$section}{$key}; if (defined $value) { $translation->removeAttribute('type'); $translation->appendText($value); # NOTE: 如果一条msg中包含了多个location,则获取了第一条有用的翻译后跳出循环 last; } } } $langContext->appendChild($_) for @msgs; saveDocument($langDom, "$outputTsDir/desktop_$lang.ts", 1); } } sub TS2Desktop { my ($desktopFile, $tsDir, $outputDesktopFile) = @_; my $contextName = 'desktop'; my $desktopCfg = Config::Tiny->read($desktopFile, 'utf8'); updateDesktopTranslation($desktopCfg , $contextName, $tsDir); writeDesktop($desktopCfg, $outputDesktopFile); } sub getEmptyContext { my ($dom, $contextNameStr) = @_; my $root = $dom->documentElement; my $context = findContext($root, $contextNameStr); if ($context) { my @oldMsgs = $context->findnodes('./message'); $context->removeChild($_) for @oldMsgs; } else { # create context $context = createDesktopTsContext($dom, $contextNameStr); $root->appendChild($context); } return $context; } sub findContext { my ($root, $name) = @_; my @ctxNames = $root->findnodes('./context/name'); for my $ctxName (@ctxNames) { my $ctxNameText = $ctxName->textContent; if ( $ctxNameText eq $name ) { return $ctxName->parentNode; } } } sub createDocument { my ($lang) = @_; my $dom = XML::LibXML::Document->new('1.0', 'utf-8'); my $dtd = $dom->createInternalSubset('TS', undef, undef); # TS my $root = $dom->createElement('TS'); $root->setAttribute('version', '2.1'); if ($lang) { $root->setAttribute('language', $lang); } $dom->setDocumentElement($root); return $dom; } sub saveDocument { my ($dom, $file, $pretty) = @_; open FH, '>', $file or die "failed to open file $file for write: $!"; print FH $dom->toString; close FH; } sub createDesktopTsContext { my ($dom, $contextNameStr) = @_; my $context = $dom->createElement('context'); my $ctxName = $dom->createElement('name'); $ctxName->appendText($contextNameStr); $context->appendChild($ctxName); return $context; } sub createDesktopTsMessages { my ($dom, $desktopCfg) = @_; # key: source, value: [ section . key, ... ] my %sourceSectionKeyMap; for my $section ( sort keys %$desktopCfg ) { # skip root section if ($section eq '_') { next; } for my $key (@localeKeys) { my $source = $desktopCfg->{$section}{$key}; if ($source) { push @{ $sourceSectionKeyMap{$source} }, "$section]$key"; } } } ### %sourceSectionKeyMap my @msgs; for my $source (sort keys %sourceSectionKeyMap) { my $locations = $sourceSectionKeyMap{ $source }; my $msg = createDesktopTsMessage($dom, $source, $locations); push @msgs, $msg; } return @msgs; } sub createDesktopTsMessage { my ($dom, $_source, $_locations) = @_; my $message = $dom->createElement('message'); for my $_location (sort @$_locations ) { my $location = $dom->createElement('location'); $location->setAttribute('filename', $_location); $location->setAttribute('line', 0); $message->appendChild($location); } my $source = $dom->createElement('source'); $source->appendText($_source); $message->appendChild($source); my $translation = $dom->createElement('translation'); $translation->setAttribute('type', 'unfinished'); $message->appendChild($translation); return $message; } sub updateDesktopTranslation { my ($desktopCfg, $contextName, $tsDir) = @_; # remove locale keys for my $section (keys %$desktopCfg) { next if $section eq '_'; for my $key (keys %{ $desktopCfg->{$section} }) { if ($key =~ /\[\w+\]/) { warn "remove $section $key"; delete $desktopCfg->{$section}{$key}; } } } # read translation my @files = getTranslationFiles($tsDir); for my $file ( @files ) { warn "read ts file $file"; my $dom = XML::LibXML->load_xml(location => $file); my $root = $dom->documentElement; my $lang = $root->getAttribute('language'); unless ($lang) { warn "language unknown in file $file"; next; } my $context = findContext($root, $contextName); unless ($context) { warn "context not found in file $file"; next; } my @msgs = $context->findnodes('./message'); for my $msg (@msgs) { my $translation = ($msg->findnodes('./translation[1]'))[0]; die "not found translation" unless $translation; my @locations = $msg->findnodes('./location'); die "not found any location" unless @locations; for my $location ( @locations) { my $value = $translation->textContent; next unless $value; my ($section, $key) = getSectionKeyWithLocationLang($location , $lang); $desktopCfg->{$section}{$key} = $value; } } } } sub getTranslationFiles { my ($tsDir) = @_; glob "$tsDir/desktop_*.ts"; } sub getDesktopLangs { my %langMap; my ($desktopCfg) = @_; for my $section (keys %$desktopCfg) { # skip root section next if $section eq '_'; my $localeKeysJoined = join '|', @localeKeys; my $regex = qr/(?:$localeKeysJoined)\[(\w+)\]/; for my $key (keys %{ $desktopCfg->{$section} }) { ### $key if ( $key =~ $regex ) { my $lang = $1; $langMap{ $lang } = 1; } } } return keys %langMap; } sub getSectionKeyWithLocationLang { my ($location, $lang) = @_; my $filename = $location->getAttribute('filename'); my ($section, $key) = split /\]/, $filename, 2; $key = $key."[$lang]"; return $section, $key; } sub writeDesktop { my ($desktopCfg, $file) = @_; open my $fh, '>:utf8', $file or die $!; printDesktop($fh, $desktopCfg); close $fh; } sub printDesktop { my ($fh, $desktopCfg) = @_; my @sections = grep { $_ ne '_' } sort keys %$desktopCfg; my @sortedSections = ('Desktop Entry'); # fill translation for (@sections) { push @sortedSections, $_ if $_ ne 'Desktop Entry'; } ### @sortedSections for my $section ( @sortedSections ) { say $fh "[$section]"; my $sectionHash = $desktopCfg->{$section}; my (@noTsKeys, @tsKeys); for (sort keys %$sectionHash) { if (/\[\w+\]/) { push @tsKeys, $_; } else { push @noTsKeys, $_; } } printSectionKeys($fh, $sectionHash, \@noTsKeys); if (@tsKeys) { say $fh "\n# Translations:\n# Do not manually modify!"; printSectionKeys($fh, $sectionHash, \@tsKeys); } print $fh "\n"; } } sub printSectionKeys { my ($fh, $sectionHash, $keys) = @_; for my $key ( @$keys ) { my $value = $sectionHash->{$key}; $value =~ s/\n/ /g; say $fh "$key=$value" if $value; } } deepin-gettext-tools-1.0.10/src/example_config.ini000066400000000000000000000001451414236741000221270ustar00rootroot00000000000000[locale] langs=["zh_CN","zh_TW"] locale_dir=../locale project_name=dde-control-center source_dir=../ deepin-gettext-tools-1.0.10/src/generate_mo.py000077500000000000000000000050241414236741000213110ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2015 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. import subprocess import os import sys import argparse try: from configparser import RawConfigParser as ConfigParser except ImportError: from ConfigParser import RawConfigParser as ConfigParser def main(args): # Read config options. config_path = args.file copy = args.copy config_parser = ConfigParser() config_parser.read(config_path) config_dir = os.path.dirname(os.path.realpath(config_path)) os.chdir(config_dir) project_name = config_parser.get("locale", "project_name") locale_dir = os.path.abspath(config_parser.get("locale", "locale_dir")) mo_locale_dir = os.path.join(locale_dir, "mo") for f in os.listdir(locale_dir): lang, ext = os.path.splitext(f) if ext == ".po": mo_dir = os.path.join(mo_locale_dir, lang, "LC_MESSAGES") mo_path = os.path.join(mo_dir, "%s.mo" % project_name) po_path = os.path.join(locale_dir, f) subprocess.call( "mkdir -p %s" % mo_dir, shell=True ) subprocess.check_call( "msgfmt -o %s %s" % (mo_path, po_path), shell=True ) if copy: subprocess.call( "sudo cp -r %s %s" % ( os.path.join(mo_locale_dir, lang), "/usr/share/locale/"), shell=True ) return 0 def valid_path(string): """ check if the path entered is a valid one """ if not os.path.isfile(string): msg = "%s is not a valid file" % string raise argparse.ArgumentTypeError(msg) return string if __name__ == "__main__": parser = argparse.ArgumentParser( description='Scan po files and generate mo files according to the ini config file', epilog='A mo folder will be generated in the locale directory') parser.add_argument('file',metavar='file', type=valid_path, help='A valid ini config path, full or local.') parser.add_argument('--copy', dest='copy', action='store_true', help='Execute "sudo cp *.mo /usr/share/locale"') args = parser.parse_args() sys.exit(main(args)) deepin-gettext-tools-1.0.10/src/policy_ts_convert.py000077500000000000000000000174221414236741000225760ustar00rootroot00000000000000#!/usr/bin/env python3 # Copyright (C) 2017 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. import xml.etree.ElementTree as ET import sys import os from glob import glob # const attr_xml_lang = "{http://www.w3.org/XML/1998/namespace}lang" class Action: #msgs dict #descs dict #msg_src string #desc_src string def __init__(self, action_elem): self.id = action_elem.get("id") self.msgs = {} self.descs = {} for item in action_elem: if item.tag == "message": lang = item.get(attr_xml_lang) if lang is None: self.msg_src = item.text else: self.msgs[lang] = item.text if item.tag == "description": lang = item.get(attr_xml_lang) if lang is None: self.desc_src = item.text else: self.descs[lang] = item.text def get_desc_src(self): if hasattr(self, "desc_src"): return create_ts_msg(self.desc_src, None, self.id, "description") return None def get_msg_src(self): return create_ts_msg(self.msg_src, None, self.id, "message") def get_desc(self, lang): desc = self.descs.get(lang) return create_ts_msg(self.desc_src, desc, self.id, "description") def get_msg(self, lang): msg = self.msgs.get(lang) return create_ts_msg(self.msg_src, msg, self.id, "message") def get_langs(self): # return msgs and descs keys langs = {} for k in self.msgs: langs[k] = 1 for k in self.descs: langs[k] = 1 return langs.keys() def policy2ts(policyFile, outputTsDir): print("policyFile:", policyFile) os.makedirs(outputTsDir, exist_ok=True) actions = [] tree = ET.parse(policyFile) for action_elem in tree.iter("action"): action = Action(action_elem) actions.append(action) if len(actions) == 0: return ts, ctx = create_ts_doc() for action in actions: ctx.append(action.get_msg_src()) if action.get_desc_src(): ctx.append(action.get_desc_src()) outputTsFile = outputTsDir + "/policy.ts" print("outputTsFile:", outputTsFile) write_ts(ts, outputTsFile) def init(policyFile, outputTsDir): print("policyFile:", policyFile) print("outputTsDir:", outputTsDir) os.makedirs(outputTsDir, exist_ok=True) actions = [] tree = ET.parse(policyFile) for action_elem in tree.iter("action"): action = Action(action_elem) actions.append(action) if len(actions) == 0: return ts, ctx = create_ts_doc() langs = {} for action in actions: ctx.append(action.get_msg_src()) ctx.append(action.get_desc_src()) l = action.get_langs() for k in l: langs[k] = 1 write_ts(ts, outputTsDir + "/policy.ts") print(langs.keys()) for lang in langs.keys(): ts, ctx = create_ts_doc() ts.set("language", lang) for action in actions: ctx.append(action.get_msg(lang)) ctx.append(action.get_desc(lang)) write_ts(ts, outputTsDir + "/policy_" + lang +".ts") def ts2policy(policyFile, tsDir, outputPolicyFile): print("policyFile:", policyFile) print("tsDir:", tsDir) print("outputPolicyFile:", outputPolicyFile) # load ts files ts_files = glob(tsDir + "/policy_*.ts") tr_dict = {} # print("ts_files:", ts_files) for filename in ts_files: lang, msgs = load_tr(filename) tr_dict[lang] = msgs tree = ET.parse(policyFile) remove_list = [] for action_elem in tree.iter("action"): for item in action_elem: if item.tag == "message" or item.tag == "description": lang = item.get(attr_xml_lang) if lang is not None: remove_list.append((action_elem, item)) for i in remove_list: i[0].remove(i[1]) for action_elem in tree.iter("action"): action = Action(action_elem) for lang in tr_dict: d = tr_dict[lang] src = "" for ty in ["description", "message"]: if ty == "message": src = action.msg_src else: src = action.desc_src if hasattr(action, 'desc_src') else None val = d.get(action.id + "!" + ty) if val != None: source = val[0] translation = val[1] if source == src and translation != "" and translation is not None: msg = ET.SubElement(action_elem, ty) msg.set("xml:lang", lang) msg.text = translation write_policy(tree.getroot(), outputPolicyFile) def load_tr(tsFile): tree = ET.parse(tsFile) root = tree.getroot() lang = root.get("language") msgs = root.findall("./context/message") msgs_dict = {} for msg in msgs: source = msg.find("./source").text translation = msg.find("./translation").text key = msg.find("./location").get("filename") msgs_dict[key] = (source,translation) return lang, msgs_dict def create_ts_doc(): ts = ET.Element("TS") ts.set("version", "2.1") context = ET.SubElement(ts, "context") ctx_name = ET.SubElement(context, "name") ctx_name.text = "policy" return ts, context def create_ts_msg(src, translation, action_id, ty): msg = ET.Element("message") location = ET.SubElement(msg, "location") location.set("filename", action_id + "!" + ty) location.set("line", "0") source = ET.SubElement(msg, "source") source.text = src tr = ET.SubElement(msg, "translation") if translation is None: tr.set("type", "unfinished") else: tr.text = translation return msg def indent(elem, level=0, more_sibs=False): i = "\n" if level: i += (level-1) * "\t" num_kids = len(elem) if num_kids: if not elem.text or not elem.text.strip(): elem.text = i + "\t" if level: elem.text += "\t" count = 0 for kid in elem: indent(kid, level+1, count < num_kids - 1) count += 1 if not elem.tail or not elem.tail.strip(): elem.tail = i if more_sibs: elem.tail += "\t" else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i if more_sibs: elem.tail += "\t" def write_xml(root, filename, header): indent(root) content = ET.tostring(root, encoding="unicode") with open(filename, 'w', encoding="utf-8") as f: f.write(header) f.write(content) def write_ts(root, filename): header = ''' ''' write_xml(root, filename, header) def write_policy(root, filename): header = ''' ''' write_xml(root, filename, header) argv = sys.argv if len(argv) == 4 and argv[1] == "policy2ts": policy2ts(argv[2], argv[3]) elif len(argv) == 4 and argv[1] == "init": init(argv[2], argv[3]) elif len(argv) == 5 and argv[1] == "ts2policy": ts2policy(argv[2], argv[3], argv[4]) else: # print usage print(''' init policyFile outputTsDir policy2ts policyFile outputTsDir ts2policy policyFile tsDir outputPolicyFile ''') deepin-gettext-tools-1.0.10/src/update_pot.py000077500000000000000000000054421414236741000211740ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2015 Deepin Technology Co., Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. import argparse import os import re import subprocess try: from configparser import RawConfigParser as ConfigParser except ImportError: from ConfigParser import RawConfigParser as ConfigParser def update_pot(config_path): # Read config options. config_parser = ConfigParser() config_parser.read(config_path) config_dir = os.path.dirname(os.path.realpath(config_path)) os.chdir(config_dir) project_name = config_parser.get("locale", "project_name") # Source dirs are separated by blank chars source_dirs = re.split('\s+', config_parser.get("locale", "source_dir")) locale_dir = os.path.abspath(config_parser.get("locale", "locale_dir")) if not os.path.exists(locale_dir): os.makedirs(locale_dir) pot_filepath = os.path.join(locale_dir, project_name + ".pot") if os.path.exists(pot_filepath): os.remove(pot_filepath) py_source_files = [] go_source_files = [] for source_dir in source_dirs: for root, dirs, files in os.walk(source_dir): for f in files: if f.startswith("."): continue if f.endswith(".py"): py_source_files.append(os.path.join(root, f)) elif f.endswith(".go"): go_source_files.append(os.path.join(root, f)) if len(py_source_files) > 0: gen_pot(pot_filepath, ['-k_'], py_source_files) if len(go_source_files) > 0: gen_pot(pot_filepath, ['-kTr', '-C', '--from-code=utf-8'], go_source_files) def gen_pot(output, args, source_files): callargs = ['xgettext', '-F', '-o', output] if os.path.exists(output): # join messages with existing file callargs.append('-j') callargs.extend(args) #print callargs callargs.extend(source_files) subprocess.call(callargs) def valid_path(string): """ check if the path entered is a valid one """ if not os.path.isfile(string): msg = "%s is not a valid file" % string raise argparse.ArgumentTypeError(msg) return string if __name__ == "__main__": parser = argparse.ArgumentParser( description='Scan msgid and generate pot file according to the ini config file', epilog='A domain.pot file will be generated in the locale directory') parser.add_argument('file',metavar='file', type=valid_path, help='A valid ini config path, full or local.') args = parser.parse_args() update_pot(args.file)