Welcome Guest, Not a member yet? Register   Sign In
Taking care of localization (and other app development questions)

Hey all

Here I am again, asking for more advice :p

I'm working on a little cms for myself: to use in the future, as practice and maybe someday, to release it.

The basic functionality is finished and now I'm going over everything again, taking care of the finer work, setting stuff in a config file, taking care of my syntax etc etc. But this also brings forth some questions and problems I don't really know how to take care off.

1. I would like to be able to easily release the cms in several languages, so now I'm putting all strings in a language file. But what to do with longer strings? I have complete paragraphs that are multiple lines long. Is it okay that I put these in the lang file too? And what about mark up? Do I include it in the language file or not?

2. How much do you put in config files? At the moment I'm storing table names in a config file too. How often does it happen that one changes table names? Is this a good practice, or just too much code? Do you prefer storing your table names in a config file?

3. Something else that's bugging me: I have several (small) javascript files that are needed on several pages (but not all), at the moment, I just load these files as I need them... Sometimes this means 5 separate js files on a page, sometimes none. Is there a way to put all the javascript in one file, that is always loaded, but only executes the necessary code? Would this be possible by writing jquery plugins and then just calling the required plugin when needed?

4. One last thing for now: I use an auth library I wrote myself. I'm a strong believer that libraries should be things that can be used on several apps (the opposite of models, that are app specific). My library has all the methods my project needs (methods that refer to fetching userdata, restrictions etc). However, I have a content controller (and model) that rely on my user table to store who editted which pages when. Do you have had this "problem" before, and how did you solve it? I guess I could also follow the logic "a model is app specific, and since the library is part of the app, the model can rely on that library.

I know there's no right answer to any of my "problems". A lot of these things are pure preference offcourse, but I'd still like some input from you guys. So thanks for reading this chunk of text :p

1. I'd have to say it depends exactly how much text you have to store in the file. If you need to store paragraphs of text, then I'd recommend you break things down so you don't have a big-a$$ file being loaded each time your CMS runs. So essentially, you'd have several language files or more for each language. The only other alternative I can think of, is to store this information in your database, but I think that would make things too complicated, and you'd be screwed if you had a database error.

2. If you feel that you want that feature, then you don't really have much choice. If something is configurable, it has to be configured somewhere. I'd suggest forcing the user to use a specific table name. That way your installer can take care of everything, and your users can have their Web site up and running in minutes. How about you keep table names out of the config file, and let you're code store the defaults. If the user wants to change a table, they can add an override to the configuration file? Personally, I still think they should stick to the names you've chosen, and just let them choose a prefix to prevent clashes if they need to share a database.

3. If they are in separate files I can only assume that's for a reason. I'd suggest using a simple asset manager or something. I just created one myself. It's fairly simple. It loads any scripts/CSS common to all pages via the config file, and then I can add script/CSS files and meta data on the fly. I have a __toString() method which allows me to echo $this->assets in my HTML head, and Robert's ya father's brother!

4. I'm not sure I understand this problem. All of this wouldn't be done via the auth library, it would be done using another library wouldn't it?

1. I'd recommend one file which gets autoloaded with all the common strings, and then to load another language file based on the controller.method, which has all the paragraphs. I would also avoid keeping markup in there, as if you want to change something (that being said, assuming they're marked up semantically, you can use CSS)

2. I personally wouldn't bother letting the table names be configurable, just the preffix. I've yet to come accross any web application/CMS/other with customizable table names. Also the overhead you constantly fetching table names from the config file might add up.
If you decide you really want to have customizable names, and want to minimize the hit on performance, you could always use defines (and its also less writting when you call it.

3. I've seen it done with multiple CSS files, where they're concatenated into a single file, and sent to the browser, this reduces the number of HTTP requests, but thats only really beneficial if you expect a lot of heavy traffic. The benefit of having it all in a single file, is it'll be downloaded once, and then cached on the users system. Although if you've just got 5 files, and as TheFuzzyOne said, they're probably split up for a reason, so I'd leave them... Especially if they're javascript libraries, as you want to be able to upgrade each one easily.

1. If you have so much text to display, maybe you should consider having views that are language specific. Then, just load the view for that language. One problem with this approach would be that if you update your design, you'd have to update multiple views. But, it might help you solve your problem for other reasons. Storing the info in a DB might not be a bad idea, especially if you are caching the pages.

2. Years ago, I saw many hosts that only allowed 1 database per account. It was very common that applications would have a table prefix (some still do) so your table names wouldn't clash with other applications' table names. Most hosts now provide plenty of databases. If your building an in-house app, this probably isn't a problem either. I would recommend hard-coding the table names. In the highly unlikely chance that you do need to rename, you can always do a search/replace.

3. If your js code is all inside functions, then you can easily put them together and load one file on every page (it only gets downloaded to the client once). Then, adapt your code to call the functions as needed. Example. One view has a function call but another view does not.

4. I agree with you. No reason a model can't have a library that accesses the database.

Good luck with your project.

Theme © iAndrew 2016 - Forum software by © MyBB