Skip to content

Instantly share code, notes, and snippets.

@JSpiner
Created October 28, 2016 12:16
Show Gist options
  • Save JSpiner/ce3e86ff3fb4e5070c753b330e007517 to your computer and use it in GitHub Desktop.
Save JSpiner/ce3e86ff3fb4e5070c753b330e007517 to your computer and use it in GitHub Desktop.
multi lang support test.md

1번방법

static.py

CODE_LANG_KR = 1
CODE_LNAG_EN = 2

CODE_TEXT_HELLO_WORLD   = 1
CODE_TEXT_GOOD_BYE      = 2
CODE_TEXT_START_GAME    = 3

def getText(textCode, langCode):
  langString = db.query( text_code = textCode and lang_code = langCode)
  return langString

app.py

#잘가요 라는 문장을 언어별로 출력할때
teamLang = db.query(select team_lang from team where team_id = team_id)
print( static.getText(CODE_TEXT_GOOD_BYE, teamLang)

2번 방법

static.py

KR_TEXT_HELLO_WORLD   = "안녕"
KR_TEXT_GOOD_BYE      = "잘가요"
KR_TEXT_START_GAME    = "시작"

EN_TEXT_HELLO_WORLD   = "HELLO"
EN_TEXT_GOOD_BYE      = "GOOD BYE"
EN_TEXT_START_GAME    = "START"

app.py


#잘가요 라는 문장을 언어별로 출력할때
teamLang = db.query(select team_lang from team where team_id = team_id)
if teamLang == "kr":
  print( static.KR_TEXT_GOOD_BYE)
elif teamLang == "en":
  print( static.EN_TEXT_GOOD_BYE)

3번 방안

static.py

class KR:
    TEXT_HELLO_WORLD   = "안녕"
    TEXT_GOOD_BYE      = "잘가요"
    TEXT_START_GAME    = "시작"
    
class EN:
    TEXT_HELLO_WORLD   = "HELLO"
    TEXT_GOOD_BYE      = "GOOD BYE"
    TEXT_START_GAME    = "START"
    
def lang(lang):
  if lang == "kr":
    return KR
  elif lang == "en":
    return EN

app.py

#잘가요 라는 문장을 언어별로 출력할때
teamLang = db.query(select team_lang from team where team_id = team_id)
print( static.lang(teamLang).TEXT_GOOD_BYE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment