Maybe it's the rum talking... (language editing for plugins)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
...but I just had a wicked idea. And this is like da bomb because it solves an awful lot of headaches very quickly.

For most plugins, they'll have their language files and keep them to themselves like good little plugins. But some plugins are not so well behaved because they'll need to load language files in other contexts. Probably the biggest example is menu items.

Now, I want to have a menu editor function in the core - some day - but the biggest problem is handling language items and doubly so for plugins. How can we have them around and loaded, and still do it efficiently?

And it occurred to me... no, I don't mean reinstating that shitfest Modifications.language.php, that shit can remain dead and buried. No, what I had in mind was far more elegant.

Menu items are needed every page, right? That means, essentially, wherever loadLanguage('index') is called, the menu items are needed. So why not have some facility whereby a plugin's language strings can be injected into the database? Obviously I wouldn't be expecting language files to do their own DB inserts, but I'd probably have a facility in the plugin-info.xml that says to load a given language and append it to an existing set of entries. That way if a plugin wants to add a new menu item, it just has to add its language file correctly, the plugin manager kicks it into the DB, recaches etc. and then it's available without having to load an extra file.

Then the menu editor just becomes some juggling of arrays and cache items, plus any other plugin that wants language strings 'everywhere' can just append them where it needs them if that makes sense.

If it doesn't, just prod me in the morning and I'll see if it still makes sense :D
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #1, on March 4th, 2013, 10:05 AM »
Why not move the entire language structure to XML file which is directly loaded into DB, and automatically loaded when the plugin is requested? Hell that way you can have a central translation repository through some official mirror which is loaded via the plugin server.
The way it's meant to be

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #2, on March 4th, 2013, 04:23 PM »
It did occur to me, however I see no need to complicate Nao's and my lives any more than necessary with language changes!

That, and the fact that chunking up the DB like that is messy especially when a large block of the default stuff will never change anyway. Though it would solve some of the adding-language-files issues.

But really the suggestion wasn't about moving everything to the database, but just allowing plugins to prepopulate stuff so it gets picked up downstream easily.

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #3, on March 4th, 2013, 04:46 PM »
I'm a bit tired of the XML syntax, especially these days, since I had to refactor an Ajax query to return plain text due to a bug in jQuery 2.0 beta 1 (which was fixed in beta 2, and my bug report is the first on their changelog, yay :P)

I'd tend to favor plain text or JSON...
Anyway.
Oh, that reminds me -- I've recently read that the CDATA stuff inside script tags was only needed for XHTML pages. Which makes sense... And that since Wedge is using HTML5, there's no need for them at all. So I'll remove them. I'm only postponing because I'm not exactly sure whether I can also remove the HTML comments around script text... And yes, I think I can. I think it's an old thing related to some old browser that reacted badly to these things.

I'll just need to gather data on that.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #4, on March 4th, 2013, 04:51 PM »
I don't personally care about the exchange mechanism. I just have an issue with dumping 650KB of data *per language* into the database in quite literally thousands of rows, especially when for the most part people aren't going to change large chunks of it.

There's also little reason to use XML itself, all we need is the ability to have named keys with potentially a named array of contents, which is easily doable in JSON.

For script tags, sure, though I remember it being a good idea even for HTML 4 pages back in the day, even though the script tag is fully declared up front as being CDATA in the spec. I see little reason why it should be an issue now.

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #5, on March 4th, 2013, 05:10 PM »
I'm not a big fan of using the database to handle things that are already in 'master' files, either, but whatever makes sense to you, as long as you handle language caching, i.e. updating stuff whenever a file is being updated by FTP.
Remember how I always hated when you moved bbcode to the database and didn't write an editor for these..? ;)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #6, on March 4th, 2013, 05:13 PM »
Yup, the whole point of the language stuff is that it reflects a delta from the master files only. That's all you really need.

I'm just trying to think of ways to make it easier for plugins.

I could have done the caching by way of using the natural cache system but I actually concluded that would make more of a mess in the long run and I wanted to keep performance tight. But yes, I'll add some way to flush the language files cache for you.

And yes, I know there's a need for a bbcode editor :P It's on my todo list!

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #7, on March 4th, 2013, 06:45 PM »
Actually, I think it'd be nice to have a general 'flush cache' button or menu entry, accessible from any non-admin page if you're an admin. (Or something...)
This would empty the language, css, js and file cache all in one go. Basically: "if you're having trouble, hit the button. If it doesn't fix anything, then come to us."

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #8, on March 4th, 2013, 06:49 PM »
Quote
Actually, I think it'd be nice to have a general 'flush cache' button or menu entry, accessible from any non-admin page if you're an admin. (Or something...)
Admin > Maintenance > Routine > bottom option

I wouldn't encourage it everywhere.

Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #9, on March 4th, 2013, 06:57 PM »
I like the idea of use of the cache file, and I was going mention this yesterday, but I'm not that well with the code deal.
Is there or could there be a way to just flush chosen Cache files? The DB storage maybe limited on some hosts, so the cache may be the thing, Don't know what I'm talking about , that's just the thought I had at the time. :)

regards,
Maxx

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #10, on March 4th, 2013, 07:03 PM »
Quote from Arantor on March 4th, 2013, 06:49 PM
Quote
Actually, I think it'd be nice to have a general 'flush cache' button or menu entry, accessible from any non-admin page if you're an admin. (Or something...)
Admin > Maintenance > Routine > bottom option

I wouldn't encourage it everywhere.
Doesn't that only do the file cache, really...? At least that's what the option is advertising itself as doing.

Why wouldn't you encourage its use? If anything, it could save us a lot of support requests, at least in the areas where caching is not directly flushed by a new upload (and I don't really plan to stick with my expensive file date searches on every single page load just to ensure we're using the latest version of the JS and CSS files....)

Also, I noticed that the error log is in English, while my page is in French... Is it as desired? I thought the error messages were logged as language-independent strings, but maybe that's only the case of Dragooon's error log implementation in SMG/Aeva Media..?! Can't remember.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #11, on March 4th, 2013, 07:06 PM »
Quote
Doesn't that only do the file cache, really...? At least that's what the option is advertising itself as doing.
Yes. Except the JS, the CSS and the language cache should all be updated by that too!

My concern is that making it too easy to clear the cache will add a lot of load unnecessarily. The language cache for example should only be needed if people touch the files directly, which will be us and upgrading only in theory.
Quote
Also, I noticed that the error log is in English, while my page is in French... Is it as desired? I thought the error messages were logged as language-independent strings, but maybe that's only the case of Dragooon's error log implementation in SMG/Aeva Media..?! Can't remember.
Depends on the error. What errors?

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #12, on March 4th, 2013, 07:17 PM »
- Then we need to update the language string to say it empties the entire cache, not just the 'file' cache. (Also, when APC or whatever is enabled, as in here, it doesn't really empty a file cache... Heck, I'm not sure it empties the data cache at all... :P)

- That's the thing, if only a handful of people can use that option, e.g. those with FTP access, it would also save us the hassle of checking too carefully for any outdated cache entries, and at the same time there could be no abuse because we're talking about users who know exactly when they could have to empty the cache, i.e. they just uploaded something, and the website is suddenly broken or misbehaves...

- Everything currently in this error log... :^^;:

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Maybe it's the rum talking... (language editing for plugins)
« Reply #13, on March 4th, 2013, 07:23 PM »
I'm not sure you *can* flush the other caches as such.

But I guess we can put a big old button on the front page or something for real admins (actual group 1 members, not just people with other access rights to the admin panel)

As far as everything in the error log, it will dump the error into the error log using English (if it's an actual PHP error), or whatever language the user is using when the error is logged.