Why this function doesn't work.
var result = confirm(OW.getLanguageText('plugin', 'test'));
Shows as plugin+test. The key is not empty!
Why this function doesn't work.
var result = confirm(OW.getLanguageText('plugin', 'test'));
Shows as plugin+test. The key is not empty!
First in your php gave you need to get a copy of the language instance if you want to its not necessary just less typing
Its not OW.getLanguage its
$language = OW::getLanguage(); you forgot the ::
Then text is an object... we know this by the -> remember an old php rule.... you shoot objects with arrows, thats how i always kept it straight between objects and arrays.
so that has an arrow -> so its an object.
you forgot to tell it its an object like so
OW::getLanguage()->text('plugin', 'keyname'));
Use the keyname, if your going to just use plane text then just put text you dont need getlanguage at all.
I would do it this way since i have the language instance.
$language->text('plugin', 'keyname')); which is the same as
OW::getLanguage()->text('plugin', 'keyname'));
i am confused about the var result =.. are you trying to use that in php or html or js. Remember smarty does it differently if you want to use that in html using js
in smarty html you would do it like so..
this would be a delete link
<a href="{$item.deleteurl}" onclick="return confirm('{text key='base+are_you_sure'}');">{text key='pluginname+keyname'}</a>
$item.deleteurl is assigned by the data array in the php file as the url with id and uses the php function that deletes the file
hope that helps...
on the html side you can pass that value to js like so
{literal}
<script type="text/javascript">
"use strict";
var text = {/literal} '{text key="pluginname+key"}'{literal};
</script>
{/literal}
any value that you have passed from php to smarty can also be passed to js in the html file in the same way.
var value = {/literal} '{$value}' {literal};
$.ajax({ | |
url: $(this).attr('url'), | |
cache: false, | |
type: 'POST', | |
dataType: 'json', | |
success: function( data ) | |
{ | |
// TODO show message | |
OW.info(OW.getLanguageText('photo', 'approve_success_message')); | |
$('#photo-approve').parent().remove(); | |
} | |
}) | |
}); How foes it work here |
Thanks Dave. Take a look at this code from photo.js
$.ajax({url: $(this).attr('url'),cache: false,type: 'POST',dataType: 'json',success: function( data ){// TODO show messageOW.info(OW.getLanguageText('photo', 'approve_success_message'));$('#photo-approve').parent().remove();}})}); How foes it work here
Ajax is how you process data in the background without loading a new page. Its normally used to run a php file for example and return the results with no new page load. It is written in a js file.
url is the url of the php file you want to run. This is assigned as a dynamic value passed to the html file and then passed to js, or a static value.
Cache false means that you dont want the requested page cached which is for security. Also it will allow the request to be called over and over again by other users.
Type is the type of reqest, a POST request.
Datatype json is a secured way to save the data returned from the request
Then you check for success and run everything in the success section if returns data.
If not success then it will skip the success section and fall down to a error section which you dont have in your sample.
You also have not assigned the data which would go after datatype
example (this is what is passed to the php file for processing)
data: {
id: parseInt(id),
url: url,
ajax: true
},
You set ajax true so that the php file can check to see if ajax is set to true, if not then the php file will exit.
after the sucess closes you would add something like this for error
error: function(errorThrown){
console.log('There is an error with AJAX! - code 5');
}
this will show up in the console log so you know where to look in the code for the error,.
hope that helps.
I am not a js pro but
this.getLanguageText = function(prefix, key, assignedVars)
so it should work if you call it with OW. as you did...mmmmmmm
im really not sure why it does not work for you.... OW should be global im thinking...
what about assigning it to a var..
var value = OW. blah blah blah
console.log('value');
So you actually have a plugin called plugin? and a key named test?Why this function doesn't work.
var result = confirm(OW.getLanguageText('plugin', 'test'));
Shows as plugin+test. The key is not empty!
or was that just an example for here?
I have had lang keys that got stuck before meaning that they show up under language but not under the parsed, i had to export the lang for the plugin and overwrite the one in the root of the plugin and then clear cache several times and then it finally showed up. Not sure why it does that sometimes.
$language = OW::getLanguage();
$language->addKeyForJs('yourplugin', 'yourlangkey');
Now you can get this text from javascript in any place using this JS code:
OW.getLanguageText('yourplugin', 'yourlangkey');
Senior Developer.
Yeah SD is the js man, he runs circles around me in js, he is very good at it.