0

I have a flutter project where I am trying the translation feature as I am new to it. the code works for most of the files but only the below code have the issue where I am using a python script to convert json to arb file. there is a script where arb to json is created and its working fine.

the beginning of both the file is same but this one gives error and other one runs fine...

below is the file

import json, glob, os, collections
from collections import OrderedDict

folder_path = 'lib/l10n/arb/'
json_folder_path = 'lib/l10n/json/'

for jsonFileName in glob.glob(os.path.join(json_folder_path, 'intl_*.json')):
    with open(jsonFileName, 'r+') as json_file:
        currentJson = json.load(json_file, object_pairs_hook=OrderedDict)
        arbName = jsonFileName.split('/')[-1].replace('json','arb')
        arbFileName = os.path.join(folder_path, arbName)
        with open(arbFileName, 'r+') as arb_file:
            currentArb = json.load(arb_file, object_pairs_hook=OrderedDict)
            for item in currentJson:
                currentArb[item] = currentJson[item]
            arbString = json.dumps(currentArb, indent=2)
            arb_file.seek(0)
            arb_file.write(arbString)
            arb_file.truncate()

error code:

scripts/localization/json_to_arb.py: line 1: import: command not found
from: can't read /var/mail/collections
scripts/localization/json_to_arb.py: line 4: folder_path: command not found
scripts/localization/json_to_arb.py: line 5: json_folder_path: command not found
scripts/localization/json_to_arb.py: line 7: syntax error near unexpected token `('
scripts/localization/json_to_arb.py: line 7: `for jsonFileName in glob.glob(os.path.join(json_folder_path, 'intl_*.json')):'

oguz ismail
  • 1
  • 16
  • 47
  • 69
princeoo7
  • 1,071
  • 3
  • 21
  • 44

1 Answers1

2

If you're using a UNIX based OS, you must add the following line at the very beginning:

#!/usr/bin/python

Hope this helps :)

Sahith Kurapati
  • 1,617
  • 10
  • 14
  • That didn't worked for me. Plus as I have stated that the other file works well and starting on both the files are same. so if that the above case was the issue, I would have errors on both the files and not only this one. – princeoo7 Jun 22 '20 at 12:19