Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Here is a JSON-based solution, with the same concept exposed by KaarezKaarez

languages.json

{
 "fr" : {
   "turn left" : "tournez à gauche s'il vous plaît" 
 },
 "en" : {
   "turn left" : "turn left please"
 }
}

And then, using the json module:

import json

with open('languages.json') as fd:
    lang = json.load(fd)

print(lang["fr"]["turn left"])

However, note that a JSON file could be bigger than a txt file.

Here is a JSON-based solution, with the same concept exposed by Kaarez

languages.json

{
 "fr" : {
   "turn left" : "tournez à gauche s'il vous plaît" 
 },
 "en" : {
   "turn left" : "turn left please"
 }
}

And then, using the json module:

import json

with open('languages.json') as fd:
    lang = json.load(fd)

print(lang["fr"]["turn left"])

However, note that a JSON file could be bigger than a txt file.

Here is a JSON-based solution, with the same concept exposed by Kaarez

languages.json

{
 "fr" : {
   "turn left" : "tournez à gauche s'il vous plaît" 
 },
 "en" : {
   "turn left" : "turn left please"
 }
}

And then, using the json module:

import json

with open('languages.json') as fd:
    lang = json.load(fd)

print(lang["fr"]["turn left"])

However, note that a JSON file could be bigger than a txt file.

Source Link
NiziL
  • 101
  • 2

Here is a JSON-based solution, with the same concept exposed by Kaarez

languages.json

{
 "fr" : {
   "turn left" : "tournez à gauche s'il vous plaît" 
 },
 "en" : {
   "turn left" : "turn left please"
 }
}

And then, using the json module:

import json

with open('languages.json') as fd:
    lang = json.load(fd)

print(lang["fr"]["turn left"])

However, note that a JSON file could be bigger than a txt file.