infogulch / xtemplate

A html/template-based hypertext preprocessor and rapid application development web server written in Go.
Apache License 2.0
73 stars 1 forks source link

Feature request: how to handle translations ? #4

Closed taophp closed 5 months ago

taophp commented 5 months ago

Currently, I see no easy, obvious way to handle T10N within xtemplate. And I don't think any ambitious web site or app should avoid this nowadays. So I'm sharing my thoughts about it below. Please, let me know what you think.

taophp commented 5 months ago

@infogulch any thoughts about this?

infogulch commented 5 months ago

I agree that i18n is important and useful.

I doubt the utility of building in an imposed file structure specifically for translated documents. The described document selection design can be implemented entirely within the template language, and in fact this is how I envisioned xtemplate being used. Templates already have access to headers, cookies, parameters, etc, and can perform complex conditionals and control flow in order to select and render the appropriate document for a particular request. Perhaps a demo or example that shows how to use xtemplate to select different versions of documents would be a good fit for this repo.

As for string translation, I could see a custom dot provider that loads and can lookup translated strings from one or more of the mentioned file formats. Then configure it to use a field name like "T" and use it like {{ .T.Tr "Sign up now for a discount!" }}.

infogulch commented 5 months ago

Even if I don't think this should be built into xtemplate, your translated document design is a pretty good starting point. If you're building something like this on xtemplate and have some issue or you'd like some input, I'd be happy to help.

taophp commented 5 months ago

@infogulch Thanks. I'll let you know.