looking to translate the page to another language. localization example of total js?.Does it translate the whole page/welcome message? - total.js

// Total.js translation file
// Created: 2014-12-18 10:32
// index.html
T80818744 : Titulok
T-52966915 : Ahoj svet!
T-1870230665 : Total.js je webový framework pre Node.js
// IMPORTANT: This line was created manually
message : Priame čítanie

Total.js can translate only phrases wrapped in #(TEXT TO LOCALIZE). First you need to define Total.js delegate onLocale which can set the language for each request:
F.onLocale = function(req) {
// req.query.*
// req.cookie('cookie_name');
// req.headers['*']
switch (req.query.langauge) {
case 'sk':
case 'cz':
case 'ru':
return req.query.langauge;
}
return 'en';
};
framework tries to find a resource file in the form /resources/YOURLANGUAGE.resource
if the file exists then the framework applies localization
otherwise the framework will use a default resource called: default.resource (if exists)
otherwise the framework use the phrases defined in views
How to create a resource file with localization?
I have prepared great utilites for localization, just install Total.js framework as a global library from NPM: $ sudo npm install -g total.js
$ cd yourapp
$ totaljs --translate
Total.js terminal app will create translate.resource file. Localize this file and copy it to /resources/YOURLANGUAGE.resource and restart app. That's all.
Example
Documentation

Related

How to use HTTP in hyperstack

I have made a basic install of a hyperstack rails app using hyperstack.org's installation instructions, trying to add a HTTP.get request in an after_mount callback.
Not really sure what else I could try, thought HTTP would be a standard option
class App < HyperComponent
include Hyperstack::Router
after_mount do
HTTP.get('/example.json')
end
render do
DIV() do
'App'
# NodeDisplay
# define routes using the Route psuedo component. Examples:
# Route('/foo', mounts: Foo) : match the path beginning with /foo and mount component Foo here
# Route('/foo') { Foo(...) } : display the contents of the block
# Route('/', exact: true, mounts: Home) : match the exact path / and mount the Home component
# Route('/user/:id/name', mounts: UserName) : path segments beginning with a colon will be captured in the match param
# see the hyper-router gem documentation for more details
end
end
end
the error received is:
Uncaught error: HTTP: uninitialized constant App::HTTP
in App (created by Hyperstack::Internal::Component::TopLevelRailsComponent)
in Hyperstack::Internal::Component::TopLevelRailsComponent
Simple answer: The HTTP library is not by default included in Opal or Hyperstack.
You can include it as part of the Opal jQuery wrapper, or with a minimal Opal Browser::HTTP library.
To add the jQuery wrapper to your Hyperstack application do the following:
Import the Hypestack jquery wrapper by adding
import 'hyperstack/component/jquery', client_only: true
to your config/initializers/hyperstack.rb file.
Then include the actual jquery javascript code in your assets:
If using webpacker run yarn add jquery in your terminal, and then add this line to the javascripts/packs/client_only.js file:
jQuery = require('jquery');
If not using webpacker instead add import 'jquery', client_only: true to the hyperstack initializer file.
If you just want to use the more minimal Browser::HTTP module, add
import 'browser/http
to your config/initializers/hyperstack.rb file.
After changing your hyperstack.rb you will have to clear the rails tmp cache by running rm -rf tmp/cache
Note: When using the browser version you will need to use Browser::HTTP instead of simply HTTP.

x/mobile: Launch a android application with given package name [String] in go

Following is the function written in go:
func LaunchApplication(packageName string) {
Query :
how can I execute application with given packageName
}
Generated the java binding [.aar] using gomobile.
I want to include .aar generated in my android application and call LaunchApplication("com.package.name") from java layer to native go layer and go layer should run the application.
In java application, following is the way to run apk using package name:
Process process = Runtime.getRuntime().exec("am start -n com.package.name/com.package.name.ActivityName");
I tried the same in go using:
os.exec() function but it is giving error that "am not found in the $PATH"
Is there is any other way to do that ?
In android, you should specify the path "/system/bin/"(/system/bin/am). Please make sure there are "am" in this path.

How to reference script files in webpack deploy?

I am using webpack and electron and while I can reference my script files fine locally (app/scripts/scriptname.sh), when it comes to the production deploy, I get an error: Can't open app/components/scripts/scriptname.sh.
It's unclear to me if this is an electron-dependent issue or a webpack-issue.
I am running these using node child_process as:
var ls = spawn('sh', ['app/components/scripts/scriptname.sh']);
I don't necessarily need the scripts to be in their own folder it would just be helpful.
You need to provide the complete absolute path to the script. To do that you can use the app.getAppPath() API of electron
app.getAppPath()
Returns String - The current application directory.
So your code would be something like:
var scriptAbsolutePath = app.getAppPath() + '/app/components/scripts/scriptname.sh';
var ls = spawn('sh', [scriptAbsolutePath]);
You can also have a look at app.getPath(name) API if it satisfies your particular requirement.

WebEssentials tslint custom rules

I have a tslint.json file in my solution directory and I'm trying to create a custom rule following the guidelines on https://www.npmjs.com/package/tslint
I have created a "nonImportsRule.ts", have copied the code from the link and have added "no-imports": true to my tslint.json file however the rule is not being picked up.
The guide says that a rulesDirectory needs to be specified, but I have no idea where this should be configured?
Also - is it possible to setup Web Essentials to break the build if tslint rules are violated?
I had a same kind of a problem. I wanted to use the TSLint extensions, tslint-microsoft-contrib and codelyzer, together with Web Analyzer. This did not work. The first step to figure out why was to make an adaptation in server.js which can be found in C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75. I changed the TSLint function into:
tslint: function (configFile, files) {
// Try catch tslint errors
try {
var tslint = require("tslint");
var options = {
formatter: "json",
configuration: JSON.parse(fs.readFileSync(configFile, "utf8").trim())
};
var results = [];
for (var i = 0; i < files.length; i++) {
var file = files[i];
var ll = new tslint(file, fs.readFileSync(file, "utf8"), options);
results = results.concat(JSON.parse(ll.lint().output));
}
} catch(error) {
// Return tslint error to visual studio so we can get some ideas for counter measures.
var result = JSON.parse('[{"endPosition": {"character": 0,"line": 0,"position": 0},"failure": "INSTALL ERROR","name": "/","ruleName": "INSTALL ERROR","startPosition": {"character": 0,"line": 0,"position": 0}}]');
result[0].failure = error.message;
return result;
}
return results;
},
The alternation resulted in error feedback in the visual studio error list when I run the Web Analyzer. Do not forget to force a new instance of node.exe with the task manager after you have applied the alternation. The feedback leaded, for my particular situation, to the following installation of npm packages in the following directories:
Packages:
"codelyzer": "0.0.12"
"tslint": "^3.7.3"
"tslint-microsoft-contrib": "^2.0.2"
"typescript": "^1.8.9"
Directories:
C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
After this, Web Analyzer was able to use the same tslint rules as my grunt task. Hopefully a newer version of Web Analyzer will solve my problems more elegantly.
Okay, i'm not using Web Essentials extension but Web Analyzer : https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d
So i won't be able to answer on this question 100%, but i want to summarize here my experience with custom tslint rules. First of all, what is not completely clear from documentation is that the whole thing depends on node.js.
So first of all you need to install node js. This will give you npm command to your command line.
After install with npm tslint and typescript. https://github.com/palantir/tslint here are examples. These will create files in : "c:\Users[Username]\AppData\Roaming\npm\node_modules"
Go into "c:\Users[Username]\AppData\Roaming\npm\node_modules\tslint\lib\rules\". Create here noImportRule.ts. Copy the following content:
import * as ts from "typescript";
import * as Lint from "../lint";
export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "import statement forbidden EDE";
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoImportsWalker(sourceFile, this.getOptions()));
}
}
// The walker takes care of all the work.
class NoImportsWalker extends Lint.RuleWalker {
public visitImportDeclaration(node: ts.ImportDeclaration) {
// create a failure at the current position
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
// call the base version of this visitor to actually parse this node
super.visitImportDeclaration(node);
}
}
Note that in the example import lint is not given with relative path that won't work with this approach.
4. Fire the command : "tsc -m commonjs --noImplicitAny .\noImportsRule.ts". This will compile your custom rule's ts. You will get bunch of compilation errors, such as: ../enableDisableRules.d.ts(1,21): error TS2307: Cannot find module 'typescript'. That's a good question why are these thrown, but forget about them, js file will be generated anyway.
5. Put "no-imports": true to your tslint.json(for now this should be custom one). With this command from command line:
tslint -c 'sample.tslint.json' test.ts
you will get:
test.ts[1, 1]: import statement forbidden. So you made the custom rule working!!! :)
That's all for working from command line. In addition I made custom rules working with WebAnalyzer, at least temporary.
I needed to copy my custom rule's files here:
c:\Users[Username]\AppData\Local\Temp\WebAnalyzer1.6.65\node_modules\tslint\lib\rules\ and of course configure WebAnalyzer tslint.json to include custom rules.
I have no idea how Web Essentials extension makes this whole thing working with tslint, but i guess some way similar :). Somewhere there should be a folder (node_modules\tslint\lib\rules) with rules what tslint uses. There you need to copy your custom ones.
Of course the most elegant solution would be to modify Web Essentials extension itself and make the tslint's custom rules directory configurable from visual studio. (so my solution is just a workaround)
Here is my custom rule example in the visual studio warning's list:

self hosted vnext application

I was wondering if I could refactor a self-hosted app (console app that starts and displays the URL of the webservices it provides) for it to work on pure vnext instead of owin.
The owin code is the following
namespace Selfhostingtest
{
class Program
{
static void Main(string[] args)
{
String strHostName = string.Empty;
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
var options = new StartOptions();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
}
}
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Razor server is running. Press enter to shut down...");
Console.ReadLine();
}
}
}
}
For the record, I don't want to use the "k web" command line start. I want to fully package the vnext app as an executable file.
Instead of Microsoft.Owin.Hosting, the Microsoft.AspNet.Hosting should be used (same class as in the "k web" command definition. Keep in mind that Owin Startup expects IAppBuilder and the vnext expects IBuilder.
In ASP.NET vNext you cannot build an EXE file, but you can definitely package up an app to be self-contained. Check out the kpm pack command that you can run in your app's folder. It will package up all the dependencies as well as generate the command scripts that you can use (instead of using k web etc.). Ultimately if you look at what k web does, it's just some shell scripts that end up running klr.exe with various parameters to indicate what it should start.
The project wiki has some basic information on the kpm tool's various options: https://github.com/aspnet/Home/wiki/Package-Manager
Here is the command line help for kpm pack to give you an idea of what it can do.
Usage: kpm pack [arguments] [options]
Arguments:
[project] Path to project, default is current directory
Options:
-o|--out <PATH> Where does it go
--configuration <CONFIGURATION> The configuration to use for deployment
--overwrite Remove existing files in target folders
--no-source Don't include sources of project dependencies
--runtime <KRE> Names or paths to KRE files to include
--appfolder <NAME> Determine the name of the application primary folder
-?|-h|--help Show help information

Resources