Hello I am developing app on angular and I use angular translate plugin with static file loader. Everything works fine but I have question is there a way to set a defaul language? I know that you can set a fallbackLanguage but it doesn't work for me or maybe it doesn't work with static file loader? I mean that in my app language is loaded via user setting in system (by sysytem here I mean our database holds what user culture type is) so there can be a user that has some strange locale set and app doesn't have translations for it than I would like to show it in English by default, same thing would come when there is missing translation for users language. Here is way I set up whole translateProvider:
$translateProvider.useStaticFilesLoader({
prefix: '/languages/',
suffix: '.json'
});
$translateProvider.fallbackLanguage('en_US');
$translateProvider.preferredLanguage('pl_PL');
And way I think of it is: if I don't have pl_PL.json file en_US.json should be loaded but instead in template the key isn't translated but just printed. Maybe I need to do dometing more?
$translateProvider.preferredLanguage('en_US');
You don't know that the user wants pl_PL during app initialisation; you have to wait until you've checked your database and then call $translate.uses('pl_PL'); to override the preferred language.
Related
The app was written by C# (MVC), combining ts and js as front end. The problem is: I am in ViewA(written with ts) that need to navigate to ViewB(written with js), before the navigation, I need to retrieve some data(check if ViewB has drafted conversation) from ViewB and pop up a window to ask the user to stay or discard drafted conversation.
There are many ways to fix the problem, but each has some issues to solve.
If I check from ViewA(ts), how do I get the data from ViewB(js)?
I can navigate to ViewB and pop up a window, but the draftedConversation object will be erased in C# controller file during onParametersUpdated, which means before it reaches to OnActivate() of the ViewB js file, the data will be erased, and can not do the checking. Is there a way to popup a window in C# file? I saw it usually does it on js file, not sure if that breaks the MVC rule.
If those two ways do not work, I might need to refactor the c# controller file. any suggestion will be appreciated, thanks!
I want to modify the CSS file using data that I get from the database. So, after the login, I am getting all the necessary data from DB and update styleSheet using insertRule/deleteRule methods then, redirect to the main page.
Login -> Theme engine page (modify css) -> home page
Theme engine page (theme.html) is an empty HTML page with one JS file (themeEngine.js) which modifies CSS file.
I checked the stylesheet in theme.html it is same as the expected result but, when it redirects to home page the CSS file goes back to its default version. The methods insertRule/deleteRule is not altering an actual file!
I tried importing themeEngine.js to every existing HTML file but in that case, default style appears (for a little amount of time, depending on the internet speed) before the theme engine starts to work and importing js file to every page is quite inconvenient.
I would like to know how can I solve this problem: having a custom style for every user. Is it possible to edit an actual CSS file using JavaScript?
Browsers can't change data on a server without explicit support from it by the server. (Imagine how long the Google homepage would survive otherwise!)
Typically you would need to pick a server-side programming language, use it to write an API, and then interact with it using Ajax.
Still very much a beginner to Android and Java, so thanks in advance for your patience!
I am trying to find a means of passing a file path (which could be in the form of a simple string or integer) from an activity (in Java) to a WebView (which is rendering a static local html file that is running JS). The issue is complicated by the fact that I am using an AR SDK (Wikitude) and the port to the SDK uses their own customised WebView(which also renders a CameraSurfaceView simultaneously) - controlling their suite is then done in a JS file loaded by the html file.
Any solution is welcome, I am new to Android so don't even know where to begin on this one. In simplest terms, I want to take a chosen option from one activity and use that information to tell my JS file what asset to load/render. If this were a web app you could use some templating to load a dynamic variable into your html (e.g. Using erb in ruby or moustache in JS).
If there is no equivalent for templating Java into a JS file, my current best guess is to write a JSON object using JsonWriter in the activity and subsequently load that file in the JS, if this is indeed the best solution, I am struggling to navigate the internal / external storage of android relative to the assets folder of my app - can anyone shed some light on how I would do that?
I've tried to keep this as general as possible, code can be provided on request.
you can pass chosen option from one activity when you are starting second activity with following code.
//Code to start another activity
Intent intent = new Intent(MainActivity.this, Second_Activity.class);
pass the value with intent
intent.putExtra("choice1", "choice1");
intent.putExtra("choice1", "choice1");
startActivity(intent);
now in second activity onCreate() you can receive these value from intent using following code
String choice1 = getIntent().getStringExtra("choice1");
i am working on an application and i want to translate some data in my page. I am using the following angular libraries:
angular-translate and angular-translate-loader-static-files.
i have write these config method:
myApp.config(['$translateProvider', function($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: appdifConst.context + '/messages/messages_',
suffix: '.json'
});
$translateProvider.preferredLanguage('en');
}]);
As it seem i get all the json files from /message/messages_*.json when my application starts.
What i want, is to configure this method above in a way that, when my application start to load, only one of the files (for example english which is the predefined) to loaded and when i click on a link (for example fr) the appi to make a post ajax request and brings the messages_fr.json back.
How is that possible?
Actually, what you want is exactly what angular-translate does. It only loads the language that is currently requested (in your case 'en'). What version do you use?
This sounds like a bug on your side to me, because there's one thing I don't understand..
You say that angular translate downloads ALL the json files.
How does it KNOW which translations exist???
My guess is that there is code with $translationProvider.use(key) on every language you have.
Perhaps someone thought this is mandatory as part of the setup or something? otherwise it just doesn't make sense that translate will know which translations you have and download them.
I have a javascript file that other people use on their site. It creates a button and loads a css file that is hosted on our server:
style.setAttribute('href', 'http://mysite.com/assets/some.css');
The user can call it in their site like so:
<script type="text/javascript" src="http://mysite.com/global.js"></script>
I want to give the user the ability to upload their own CSS file on my web app that will replace the one that I am setting in global.js.
Currently, I added a custom_css:binary column in the Users table that will hold the CSS file, but this requires the user to stay signed in on the site. I'm not sure if this is the right way to approach this or if there is a better way to do it. Also, what are some security risks to this approach?
I'm using RoR for the backend.
Any help would be great!
UPDATE 1
I'm able to store the uploaded JS file and load the custom CSS, but it's currently checking the current_user - this means the stylesheet will not be rendered for the users. How can I work around this?
I was able to find the solution myself.
There are several ways to approach this:
Add a query string to the JS src
Scrape the page for a certain element that gets generated by your script
I opted for option 1. When I detect a dynamically generated query string, I send that over to the controller in the params hash and load the css file accordingly.