I need to implement localization using commandline arguments.
I got an answer for this
string[] cmd = Environment.GetCommandLineArgs();
What this will do is it will add all the arguments You pass through Cmd in an string Array and then you can make use of those passed arguments for a particular functionality.
As In my case if I pass "eng" as command line argument the whole application will get tht "eng" culture.
So this is how I implemented Localization using CommandLineArguments.
Related
I'm working with some legacy code that uses ParamCount() and ParamStr() in various places, and now I need to provide different values than those that were actually passed as command line variables.
The simplest solution would be to programmatically add/modify the existing command line parameters, since the alternative is to change A LOT of the legacy code to accept function parameters rather than directly accessing ParamCount() and ParamStr().
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Edit, clarification of the legacy code:
The legacy code makes some database requests, using where arguments from the command line (and sanitizing them). This is fine in 99.9% of all cases, as these arguments are fundamental for the purpose of the legacy units. However, I'm working on a new feature that "breaks the mold", where one of these fundamental arguments are unknown and need to be fetched from the database and provided internally.
Yes, I could search and replace, but my objective here is to not touch the legacy code, as it's in a unit that is shared among many different programs.
Restarting the program and/or executing a new copy of it from itself is one solution, but seems a bit risky and cumbersome. This is a production program that executes on a server and needs to be as simple and robust as possible.
Is this possible? Can I somehow add/modify parameters from within the program itself so that ParamCount() ParamStr() will pick up my new/modified parameters?
Technically yes, but it is not something that the RTL itself exposes functionality for, so you will have to implement it manually.
Since you are working with legacy code, I'm assuming you are working on Windows only. In which case, ParamStr() and ParamCount() parse the string returned by the Win32 API GetCommandLine() function in kernel32.dll.
So, one option is to simply hook the GetCommandLine() function itself at runtime, such as with Microsoft's Detours, or other similar library. Then your hook can return whatever string you want 1.
1: for that matter, you could just hook ParamCount() and ParamStr() instead, and make them return whatever you want.
Another option - which requires messing around with lower-level memory that you don't own, and I don't advise doing this - is to obtain a pointer to the PEB structure of the calling process. You can obtain that pointer using NTQueryInformationProcess(ProcessBasicInformation). The PEB contains a ProcessParameters field, which is a pointer to an RTL_USER_PROCESS_PARAMETERS struct, which contains the actual CommandLine string as a UNICODE_STRING struct. If your altered string is less then, or equal to, the length of the original command line string, you can just alter the content of the ProcessParameters.CommandLine in-place. Otherwise, you would have to allocate new memory to hold your altered string and then update ProcessParameters.CommandLine to point at that new memory.
I am using AADL which is domain specific language created using Xtext and EMF. I am trying to use function IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createFileURI("dummy.aadl")) but it returns null. how can I fix it?
It looks like you did never called the doSetup method of the AADLStandalibeSetup (or however your language impl is called). It is used to register your language if you do not run in an OSGi equinox environment.
i am currently doing an app that has language change feature. However,for every string that i wish to have changes made to when a different language is selected, i have to implement the following code
"Hello world".localize()
However, as the app gets bigger, the code become very messy in the way that all the strings in their respective view controllers have this .localize() append to it.
Is there a way where i can do this .localize() thing in one central place?
EDIT: I tried to create a Strings.swift file and put all the strings inside. I did something like this.
static let relevantString = "hello world".localize()
and then in the view controllers i call
let myString = relevantString
However, this does not well. The strings will only change after i terminate the app and restart it.
Your attempt to use static let fails to produce the dynamic behaviour you want simply because you used a constant. You could use a read only computed property instead, something like:
var relevantString : String { return "Hello World".localize() }
As an alternative, as you seem to be more concerned over the clutter, you could define a simple prefix or postfix unary operator which called localize() on its argument. Swift allows a number of symbols to be used as operators so the operator can just be a single character. For example you could define, say, § so that §"Hello World" produced a localised string.
HTH
I am using Intellij IDEA and Grails as my application framework.
My application is mainly on Groovy.
I am trying to add external custom argument as an external parameter to my application.
I have opened the Edit Configurations... and tried different ways to add custom arguments in the VM options, and inside the Program Arguments, but with no success.
Here is an example to one try I did:
I added
-Dcustom.arg=100
to the VM options.
I would like to know if it is possible to inject external variable by using the Application configuration?If yes, how should it be done?
It should be done by adding a new program argument to the Edit configuration --> Program Arguments:
Just add a new value of the custom argument such as: externalArg.
And in the application code, find the section read those properties.
For example:
Properties props = System.properties
String propValue = props.get("sun.java.command").toString()
the propValue contains all the Program Arguments and specifically the externalArg parameter you have inserted.
Another option can be done by inserting the variable into the Edit configuration --> VM Options. When using grails, the parameter should look like that:
-Dgrails.externalVariable=3
Reading the externalVariable inside the application is done by:
Object externalVariable = System.getProperties().get("grails.externalVariable")
Note:
Both of those 2 options give the same result.
Using each one of the options should be related to the variable concept.
If you wish to have the externalVariable as a program argument insert the parameter into the Program Arguments.
If you wish to have the externalVariable as a Virtual machine parameter insert the parameter into the VM Options.
I was debugging datahandler for an mvc4 application, and I came across the
AddInParameter(DbCommand, String, DbType);
and I looked for the same in MSDN, but there its mentioned as retired content and there is not much documentation. So please anybody help me to understand what it does?
1st Parameter, DbCommand - is the command you want to execute on your database, e.g. StoredProc, SqlString etc.
2nd Parameter, Parameter Name - is the name of your parameter
3rd DbType, DbType - is the type of your parameter e.g. String
Basically this will add an Input parameter which can be used in your DbCommand. The AddInParmeter method works similarly like the SqlCommand.Parameters.Add() of the System.Data.SqlClient namespace.