cp_lang.py 836 B

12345678910111213141516171819
  1. import sys, argparse
  2. parser = argparse.ArgumentParser(description="""Copies fusionpbx webapp languages. Run with 'find <fusionpbx_dir> -name app_config.php -exec python ./cp_lang.py {} en-gb en-us \;'""")
  3. parser.add_argument("php", help="app_config.php, app_languages.php or app_menu.php file path", type=str)
  4. parser.add_argument("new", help="new language code", type=str)
  5. parser.add_argument("cur", help="current language code to copy", type=str)
  6. args = parser.parse_args()
  7. with open(args.php, "r+") as f:
  8. contents = f.readlines()
  9. for index, line in enumerate(contents):
  10. find = "['{}']".format(args.cur)
  11. repl = "['{}']".format(args.new)
  12. if find in line and "['fields']" not in line:
  13. newline = line.replace(find, repl)
  14. if newline not in contents:
  15. contents.insert(index+1, newline)
  16. f.seek(0)
  17. f.writelines(contents)