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

i18n -with subdirectories, like #1369

heyt0ny opened this issue Oct 1, 2019 · 3 comments


Copy link

commented Oct 1, 2019


I'm using i18n middleware for lang localization and currently my urls look like According to many sources (e.g. it's much better to use subdirectories instead of query params. So how to make ->


@heyt0ny heyt0ny added the type:idea label Oct 1, 2019
@heyt0ny heyt0ny changed the title i18n - like i18n -with subdirectories, like Oct 1, 2019

This comment has been minimized.

Copy link

commented Oct 1, 2019

Hello @heyt0ny,

What i18n middleware are you using?

With both of them you can specify the way that a language is accepted.
See for example the kataras/iris/middleware/i18n will try to get the language first by language's context's key(can be customized too).


Lines 717 to 718 in df88227

// Defaults to "iris.language"
TranslateLanguageContextKey string `json:"translateLanguageContextKey,omitempty" yaml:"TranslateLanguageContextKey" toml:"TranslateLanguageContextKey"`

langKey := ctx.Application().ConfigurationReadOnly().GetTranslateLanguageContextKey()
language := ctx.Values().GetString(langKey)

setLangMiddleware := func(ctx iris.Context){
    langKey := ctx.Application().ConfigurationReadOnly().GetTranslateLanguageContextKey()
    languageByPath := ctx.Params().Get("lang") // see {lang}
    ctx.Values().Set(langKey, languageByPath)
// app or per group (routes := app.Party; routes.Use...)
app.Get("/{lang}/path", yourHandler)

This comment has been minimized.

Copy link

commented Oct 1, 2019

Thank you.

I have 2 questions though:

  1. How to apply {lang} to a lot of urls:
    Imagine I have 2 type of urls (first A without locale and second B with local): (A) and (B). If I create

A) appAssets := app.Party("/") and put A into it
B) appMultilang := app.Party("/{lang}") and put B into it

it won't understand A url and will think that {lang} = sitemap.xml. I don't think it's a good practice to check whether {lang} is one of locales, and if's not -> redirect to A. How to properly handle that?

  1. if the user enters - he will be assigned some {lang} based on some logic (that I define). How to do then this redirection (knowing {lang} value) in iris to make url look like{lang}/some-page?

This comment has been minimized.

Copy link

commented Oct 4, 2019

@heyt0ny You are welcome.You can do it understand by mapping the locale keys with the param and if it is NOT matching then redirect to the default (en-us or without param) otherwise handle the request with the specific locale. You can make use of ctx.Values() inside the app's middleware and call the necessary handlers.

However, you can describe us the net/http (or other framework at any language) way because it depends on what fits you the most, I can help you convert everything to Iris.

If you don't have any idea about it, give me time until tomorrow and I will provide such a feature (if necessary).

Please vote here as well whenever you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.