localizable.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #coding=utf-8
  2. import re
  3. import sys
  4. reload(sys)
  5. sys.setdefaultencoding('utf8')
  6. host = sys.path[0] + '/BuYao/BuYao'
  7. f=open(host + '/Public/Profile/BYHStringKeyProfile.h', "r+")
  8. f.truncate()
  9. f.write('#import <UIKit/UIKit.h>\n#import <JXHMacro.h>\n#import "BYHLocalizationManager.h"\n')
  10. f.close()
  11. f=open(host + '/Public/Profile/BYHStringKeyProfile.m', "r+")
  12. f.truncate()
  13. f.write('#import "BYHStringKeyProfile.h"')
  14. f.close()
  15. f=open(host + '/en.lproj/Localizable.strings', "r+")
  16. f.truncate()
  17. f.close()
  18. f = open(host + '/zh-Hans.lproj/Localizable.strings', 'r')
  19. lines = f.readlines()
  20. for line in lines:
  21. if line == "\n":
  22. print "换行"
  23. f = open(host + '/Public/Profile/BYHStringKeyProfile.h', 'a')
  24. f.write('\n')
  25. f.close()
  26. f = open(host + '/Public/Profile/BYHStringKeyProfile.m', 'a')
  27. f.write('\n')
  28. f.close()
  29. f = open(host + '/en.lproj/Localizable.strings', 'a')
  30. f.write('\n')
  31. f.close()
  32. continue
  33. if line.startswith('///'):
  34. print "小注释"
  35. f = open(host + '/Public/Profile/BYHStringKeyProfile.h', 'a')
  36. f.write(line[1:len(line)])
  37. f.close()
  38. f = open(host + '/Public/Profile/BYHStringKeyProfile.m', 'a')
  39. f.write(line[1:len(line)])
  40. f.close()
  41. f = open(host + '/en.lproj/Localizable.strings', 'a')
  42. f.write(line)
  43. f.close()
  44. continue
  45. if line.startswith('//'):
  46. print "大注释"
  47. f = open(host + '/Public/Profile/BYHStringKeyProfile.h', 'a')
  48. f.write('#pragma mark - ' + line[2:len(line)])
  49. f.close()
  50. f = open(host + '/Public/Profile/BYHStringKeyProfile.m', 'a')
  51. f.write('#pragma mark - ' + line[2:len(line)])
  52. f.close()
  53. f = open(host + '/en.lproj/Localizable.strings', 'a')
  54. f.write(line)
  55. f.close()
  56. continue
  57. matchObj = re.match('\"([^\"]*)\"', line, flags=0)
  58. if matchObj:
  59. f = open(host + '/Public/Profile/BYHStringKeyProfile.h', 'a')
  60. f.write('CONST_STRING_INTERFACE ' + matchObj.group(1) + 'StringKey;\n')
  61. f.close()
  62. f = open(host + '/Public/Profile/BYHStringKeyProfile.m', 'a')
  63. f.write('CONST_STRING ' + matchObj.group(1) + 'StringKey' + ' = @"' + matchObj.group(1) + '";\n')
  64. f.close()
  65. f = open(host + '/en.lproj/Localizable.strings', 'a')
  66. # f.write(matchObj.group() + ' = "";\n')
  67. f.write(line)
  68. f.close()
  69. print "matchObj.group(1) : ", matchObj.group(1)
  70. else:
  71. print "No match!!"