File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,10 +27,10 @@ You don't need to "install" anything special. Just make sure you have Python 3 (
27272 . ** File Input:**
2828
2929 Create a ` .tpy ` file containing your translatable code (e.g., ` example.tpy ` ). Then, run the compiler with the
30- filename as an argument :
30+ file path, and the dictionary path as command line arguments :
3131
3232 ``` bash
33- python lang.py example .tpy
33+ python lang.py script .tpy dict.csv
3434 ```
3535
3636# # Example
@@ -56,7 +56,7 @@ You don't need to "install" anything special. Just make sure you have Python 3 (
5656
57573. Run It:
5858 ` ` ` bash
59- python lang.py hello.tpy
59+ python lang.py hello.tpy dict.csv
6060 ` ` `
6161
62624. Output:
Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ def get_translations() -> dict[str, str]:
5757
5858 translations : dict [str , str ] = {}
5959
60- with open ('lang.csv' , encoding = 'utf-8' , newline = '' ) as f :
60+ # second command line argument is a dictionary path
61+ with open (sys .argv [2 ], encoding = 'utf-8' , newline = '' ) as f :
6162 reader = csv .reader (f )
6263 for row in reader :
6364 translations [row [0 ]] = row [1 ]
@@ -109,7 +110,7 @@ def run_program(program: str) -> None:
109110def main () -> None :
110111 """Main function: handles file input."""
111112
112- if len (sys .argv ) == 1 :
113+ if len (sys .argv ) < 3 :
113114 raise IOError ('Must Provide Additional Arguments' )
114115
115116 # Read code from file
@@ -123,7 +124,7 @@ def main() -> None:
123124
124125 python_program = translate_program (code )
125126
126- if len (sys .argv ) == 2 :
127+ if len (sys .argv ) == 3 :
127128 run_program (python_program )
128129 return
129130
File renamed without changes.
You can’t perform that action at this time.
0 commit comments