〖android〗android App Project resource string check (check for missing translations, resulting in system switching language crashes)

Source: Internet
Author: User

During the development of Android project, there is a lack of translation in English and Chinese, this Python script is used to check if the string is missing the corresponding translation

1 #!/usr/bin/env python2 #Encoding:utf-83 4 ImportOS, sys, getopt5 ImportXml.dom.minidom6 Importsubprocess7  fromXml.dom.minidomImportNode8 9 #determine if the app project is based onTenAxml='Androidmanifest.xml' One  Ares_en_string="Res/values/strings.xml" -res_cn_string="Res/values-zh-rcn/strings.xml" -  the #Check the resource file list -res_string_files=[Res_en_string, res_cn_string] -  - #Java Invoke string resource list +Find_string_called_by_java=" "Find-name repo-prune-o-name git-prune-o-type f-name "*\.java"-print0 | xargs-0 grep--color-n-O ' r.str ing[0-9a-za-z_.-]\+ ' |awk-f ': ' {print $} ' |sort|uniq|xargs echo" " -  + def_check_string_res (path): A     """checking string resource invocation conditions at  - :p Ath:todo - : Returns:todo -  -     """ - os.chdir (path) in     if  notos.path.exists (Axml): -         return to  +     #Output Hints -     Print "\n### processing Project:%s.. \ n"%Path the  *     #getting string resource invocation conditions $Find_string_called_by_java_array = subprocess. Popen (Find_string_called_by_java, Shell=true, stdout=subprocess. PIPE). Stdout.read (). Split (' ')Panax Notoginseng  -     #Check resource files one by one (currently checking Chinese, English) the      forRes_string_fileinchRes_string_files: +         Print ">>> Checking%s file :"%Res_string_file A  the         #parse the XML file and save the existing resources to Names_had +Doc =xml.dom.minidom.parse (res_string_file) -strings = Doc.getelementsbytagname ('string') $Names_had = [] $          forStringinchStrings: -Name = String.getattribute ('name') - names_had.append (name) the  -         #checks the called string resource one by one and does not exist this resource times warningWuyi          forCheckinchFind_string_called_by_java_array: theC=check[9:].strip () -             ifC not inchNames_had: Wu                 Print "-warning:string name '%s ' not found!!!"%C -  About defUsage (exitval=0): $     Print "\nusage:%s Project_dir1 project_dir2.. \ n"%Sys.argv[0] -  - if __name__=='__main__': -     ifLen (sys.argv) = = 1: A         ifOs.path.isfile (Axml): +_check_string_res (Os.path.abspath ('.')) the         Else: - usage () $     elifLen (SYS.ARGV) > 1: the          forPathinchSys.argv[1:]: the             ifOs.path.isdir (path): the _check_string_res (Os.path.abspath (path)) the             Else: -                 Print "# # #%s not a directory, ignored."%Path in     Else: theUsage ()

How to use:

./check_string_res.py packages/apps/settings/

./check_string_res.py packages/apps/settings/packages/apps/quicksearchbox/.

Match the missing string to the translation, and avoid the lack of translation causes Android to crash after switching languages;

〖android〗android App Project resource string check (check for missing translations, resulting in system switching language crashes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.