Welcome Guest, Not a member yet? Register   Sign In
Passing language strings to Javascript, view organization help
#1

I'm working on a user registration page for a site that supports multiple languages. According to the OWASP Recommendations for authentication, it's considered 'best practice' to provide users with real time feedback as to whether the password they are choosing is valid. This gets complicated for a few reasons:

1) I need to provide language strings to my Javascript
I need to feed these language strings into my view which will in turn make them available to my Javascript. I would prefer to have these strings defined somewhere in the <head></head> region of my HTML output where I would also like to define my JS that attaches onChange() events to my form inputs when I'm sure they have been defined.

2) I really want to avoid defining JS or HTML in my controllers.
CI's view implementation doesn't really lend itself all that well to nesting of complex interface elements into some other element. One typically loads views in sequence:
Code:
// a controller method
public function foo() {
 // collect $data here somehow
 $this->load->view("header"); // contains opening <body> tag, probably <head>, also HTML to define site-wide menu
 $this->load->view("some_page", $data); // data for the current page. E.g., product info or a user profile or an article or something
 $this->load->view("footer"); // maybe some google analytics stuff or something, closing </body> tag, etc.
}
If I want to get JS defined between the <head>...<head> tags in the header view, I have to either break up my header template, drastically complicating my view organization, or I must define my JS in a $variable in my controller -- this is bad form as I understand things. Shouldn't be writing PHP to generate HTML or JS strings. The sequential loading of views in this way also doesn't really seem to jibe all that well with the nested/hierarchical structure of HTML. I.e., we are often loading one view to open an element (e.g., <html>, <body>, possibly a large <div> or <form> and another, separate, view to close the HTML element with its </html> counterpart.

3) I'd prefer not to define a bunch of redundant Javascript files that are intermingled with language-specific data
While I can certainly imagine creating a bunch of JS files that define only prompts for each language so that I can separate language out from the regex logic to check one's password, it seems like poor organization to me to have these prompts intermingled with HTML and/or JS. This sort of intermingling typically makes translation work difficult because your translators need JS and/or HTML chops and awareness to avoid breaking things.

Bottom line is that it seems optimal to get my language strings from my database or from some data store and NOT have it intermingled with a bunch of HTML or JS. It also seems like I'll need to inject complex JS/HTML into my views or risk drastically complicating my view organization (and controllers) if I have to redesign these views to break them up further. The most maddening part about this will be situations where I have some opening <HTML_ELEMENT> tag in one view with its corresponding </HTML_ELEMENT> tag in another.

Can anyone offer a shrewd approach to managing views that eases this issue? I've looked at the Output class but can't really tell from the docs how I might use it to load a view and capture its contents after they are merged with data.  I can also imagine an approach using DOM but that seems like it might be complicated too.

Any help or suggestions would be greatly appreciated!
Reply


Messages In This Thread
Passing language strings to Javascript, view organization help - by sneakyimp - 01-21-2015, 12:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB