Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We can now use karax/languages from the native backend #265

Merged
merged 1 commit into from Jul 8, 2023

Conversation

planetis-m
Copy link
Contributor

@planetis-m planetis-m commented Jul 8, 2023

There is no reason not to share the Language enum between backend and frontend. With this change this is possible. You can have something like this in your server:

const
  defaultLanguage = Language.enUS

proc parseLanguage(s: string): Language =
  let i = binarySearch(languageToCode, s)
  if i >= 0: result = Language(i)
  else: result = defaultLanguage

proc getLanguage(url: Uri): Language =
  var lang = ""
  for key, val in decodeQuery(url.query):
    if key == "lang":
      lang = val
      break
  result = parseLanguage(lang)

The lang=key is send from the frontend like this:

 ajaxGet("/route?lang=" & languageToCode[getCurrentLanguage()],
                  {cstring"Accept": cstring"application/json"}, onRoute)

@Araq Araq merged commit 2371ea3 into karaxnim:master Jul 8, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants