Skip to main content
Topic: Translator (Read 7084 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Translator

It has a lot that needs to be hashed out, but with $txt being Translator, it allows you to do fallbacks when a string can't be found and allows for event listeners to be added. I wrote this out in about 30 minutes so there's going to be issues. The Language class would do the loading of the files and would return that to the Translator class. Instead of putting all of those $txt variables in a global scope, you'd return the array from the file. This also makes it possible to find what file the string is in. I would probably refactor it with the ArrayObject methods just so the IDE can give better hints.

https://gist.github.com/joshuaadickerson/8576933

An aside: you should add an event to loadLanguage() so mod authors can include their own text strings (or overwrite them) when a language file is loaded.

Re: Translator

Reply #1

Another idea I had is to use some form of namespacing in the keys themselves. For instance 'no_access' would become 'errors.no_access' and then you can find that string in Errors.{language}.php. If the string isn't found, it can attempt to load that file.

Re: Translator

Reply #2

This should lazy load the language files. If _() or loadLanguages() is called, it should load the languages instead of on load().

Re: Translator

Reply #3

Something I was just thinking of is to use and extend (or just change) this gist to log which language strings are being used on every page. I think it is a pretty good way to find out what is being used.