I'm learning best practices for internationalization and see that 'string externalization' comes up often. What does this mean? Looking up on google always results in people recommending some plugin for java, but I'm trying to come up with something on javascript.
String externalization means, instead of writing:
console.log("Hello, world");
you load the string from an external source, like a text file or a database. The code then looks like this:
console.log(gettext("Hello, world"));
The gettext function then does the whole work of loading the externalized string. This is one of the ingredients for translating software.
Related
I have some third party application that I have to use, it generates UTF16LE encoded json files.
When I put these manually on my server and try haxe generated php to parse these files, it refuses. It seems it can't detect and convert to the encoding haxe php accepts.
I don't know where to start. Converting it on the client is an impossibility, there are too many of such files and need too frequently be parsed. So I have to use php. It would be nice if haxe has a way to convert it to the encoding it accepts. I have tried RTFM, but I so far I havent found anything that says haxe can convert it. Before I start reinventing some second wheel, I rather make sure there isn't some obvious way to it with haxe.
I am using Haxe version 4.2.1+bf9ff69
What am I overlooking? Is haxe php able to solve this, or is going native php the only option?
== SOLVED ==
As these json files do not need any emoticon support or whatever characters for non-english language, my solution was to strip everything except basic printable ASCII characters.
import sys.io.File;
import php.Syntax;
// some function body
return Syntax.code('preg_replace( "/[^[:print:]]/", "",{0})',File.getContent(_path));
I couldn't share these file on the web, because of privacy concerns. Also I discovered these files had ... wait for it - double BOM's- hacked into it.The BOM detector I threw in reported the first BOM it found happening to be UTF16LE.
Enterprise spaghetti monster probably the reason. Thought I had seen it all, but with that, one probably can't never have seen it all. The wonders of human ingenuity.
Just a blunt strip instead of making my own ludicrous code to unfudge that stuff and justice served. Hurrah.
I want to see source code of the file mentioned in process.binding() statement in nodeJS source code, have seen similar question on stackoverflow but most of them answers to specific cases like fs etc.
I want explanation based on which I should be able to find any file mentioned in process.bindings().
Since this question is lying here for very long I decided to give it another try to find the answer and found one very nice presentation online.
Process.bindings presentation
To summaries this, process.bindings() binds the javascript object with the C++ object which exposes the C++ functions to be executed from javascript, essentially it creates a javascript wrapper around the C++ functions to make it available from NodeJS.
To find which C++ function is bound to which javascript function you can dig into NodeJS source tree here NodeJs source tree . Names are straightforward to map with core module names and look for signature env->SetMethod(target, "<modulename>", <C++ function name>);
Example: env->SetMethod(target, "stat", Stat);
Currently, I am working on a project to transpile from my company's in house scripting language, which is Object Orientated and takes quite a few features from other languages, into Groovy, which has many similar features.
To keep code as close to original as possible, I am trying to leave certain function names and parameters the same. To cater for this, I would like to write a set of libraries that can be imported.
For example, say I have an inbuilt method in the original scripting language,
I would like to be able to write the definition for this method in a groovy file, that can then be imported when needed, and the method may be called.
Tools.groovy
// filename: Tools.groovy
public String foo(String bar) {
return bar;
}
and in another file
Main.groovy
// filename: Main.groovy
import Tools;
String bat = foo("bar")
I know you can can compile class files into jars and put them into the class path, but a lot of the methods I will need to implement will either require meta programming or won't be associated with an object.
Sorry if it's either a bad question or not clear enough. I'm not sure whether its even possible.
Cheers
I believe you should be able to create libraries and reuse them when needed.
All you need to do is create class and add the static methods if you do not have to create instances, non static methods otherwise. Then it looks like you already aware how to proceed later.
For instance, you can create utilities classes for String, List, etc based on your description.
By the way, even if you do not create libraries, it is even possible to write one lines in groovy achieve what you may needed most of the cases.
Is it possible to parse JSON using NSJSONSerialization when running swift on ubuntu? Since foundation is available I am assuming it should be?
If not, Is there any other way of serialising and deserialising JSON in swift on linux?
NSJSONSerialization is partly implemented (serialization is not yet implemented)
do it yourself, in accordance with your needs, and you will see, that it is the best investment and great way to understand Swift and its possibilities. you can also use one of the opensource libraries available around. SwiftyJSON is very popular, for an example
As mentioned by Sebastian OsiĆski, unfortunately it use NSJSONSerialization too.
you can check this very simple, but working example swift json. it is far away to be 'perfect', but as an inspiration it could help you, i hope so.
I am using TidyJSON for this, because it combines much of the ease of SwiftyJSON but does not rely on NSJSONSerialization for parsing. It works wherever Swift works, and I'm using it just fine in my current Swift/Ubuntu projects.
If you're using the server side Swift framework "Perfect", You can do something like this to convert "data" (Binary) type to "JSONConvertable" (Swift Arrays etc) object types.
do{
let jsonObject = try String.init(data: jsonData, encoding: .utf8)?.jsonDecode()
print("\(jsonObject as! [String])")
}catch{
response.completed(status: .badRequest)
return
}
I don't really understand the readme of htmlparser.. and I searched over the internet but cannot find a proper tutorial for it (or other NodeJS parsers).
I believe for most of the time if there's no tutorial for a pretty complete and old library it's mostly because that it's easy to do thus people don't really feel the need to write tutorial for it... But I found NodeJS html parser is pretty hard to understand...
You should check out htmlparser2. It's the newer htmlparser and it's got a decent readme. The way I tend to use it isn't streamish, and thus looks something like this:
handler = new htmlparser.DomHandler(function(err, dom) {
// ... DO CODE HERE
})
new htmlparser.Parser(handler).parseComplete(html_string)
For the code inside the handler function, I use soupselect because it's documented and I'm lazy, but htmlparser2 guys suggest domutils, but it has no documentation.