I am using i18next package for NodeJS to enable translation. I am using it as standard with a json file for each language-COUNTRY pair.
I'd like to build an admin page to edit translations without having to dig into the code; then, how can I "reload" the json files once edited by admin, without having to restart the server ?
Also, is it possible to use a DB (i am using mongodb) instead of JSON files ? Would it be more appropriate in this case?
I wish i knew the answer to how to reload the JSON files without completely re-initializing i18next-node.
In terms of storing your translations in a database, i18next-node can connect to MongoDB (as well as Redis and CouchDB): http://i18next.com/node/pages/doc_init.html#backend
You can set
i18next.sync.resStore = {}
and then call
i18next.init(callback)
to force a reload of your preloaded languages.
It is better to use an official API of i18n with reloadResources.
// reload all
i18next.reloadResources();
// reload languages
i18next.reloadResources(['de', 'fr']);
// reload namespaces for all languages
i18next.reloadResources(null, ['ns1', 'ns2']);
// reload namespaces in languages
i18next.reloadResources(['de', 'fr'], ['ns1', 'ns2']);
Related
I am working on node using hapi framework. New to this so I apologize if it comes out to be very basic.
I want to access a plugin name within the plugin files.
Use case is I want to access the plugin options from the server object.
So I can do server.registrations[plugin_name].options.
My workflow at that point (where I require the options) is not inside the register method ( I run an independent script that just needs to initialize the server, not start it; so no routes here) so not able to access the options from there, but I have the server object available.
Also, what is the correct way to expose the plugin options to other files within the plugin? If I need the options after a lot of nesting of files etc , it is very chaotic to keep passing the options object somehow from file to file, method to method.
Not really clear how to work this problem out.
Not a 100% sure what your question is but if you expose your options in a script (module) that can be required by both your plugin and any other files that you want to use the same options object that will allow you to access the same object in multiple places.
Please let me know if i understood correct, you can do like this.
const Plugins = require('./Plugins');
//Register All Plugins
server.register(Plugins, err => {
if (err){
server.error(`Error while loading plugins : ${err}`)
}else {
server.log('info', 'Plugins Loaded')
}
});
Is there a service that creates basically a one-time download of a file, preferably something I can use from NodeJS?
I've done some research on FilePicker, and haven't found anything about regenerating the link it gives you for a file. There may be a way to do this with NodeJS, but I'm using Meteor at the same time so many Node things probably will conflict.
You could build it with meteor. Using meteor-router with meteorite & use server side routing to deliver the files.
You need a collection to keep track of downloaded files:
Server JS
var downloads = new Meteor.Collection("downloads");
//create a link
downloads.insert({url:"/mydownload.zip",downloaded:false})
Meteor.Router.add('/file/:id', 'GET', function(id) {
download = downloads.findOne(id);
if( download) {
if(dowload.downloaded) {
this.response.send("You've already downloaded me")
}
else
{
//I guess you could just redirect or stream the file for an extra layer of surety
this.response.redirect(download.url);
}
}
});
On the client you can use /files/{{_id}} with _id of the file from downloads the person has as the link
My recommendation would also be to add custom server-side logic to count # of uploads (or just flag a file as downloaded/not downloaded) and respond accordingly. The closest you could do with Filepicker.io would be using the security policies to restrict downloading the file to a specific time interval.
in addition to using the router package
in Meteor.startup you can add
var require = __meteor_bootstrap__.require;
fs = require( 'fs' );
the fs variable should be declared on the server only. the fs package is used by Meteor and does not need to be added separately.
once you have done this, you can create files with Meteor.uuid() as their name which makes them unique and very difficult to guess. It is also possible to delete the file after a certain amount of time by using Meteor.setTimeout
the question is: where do the files to be downloaded come from?
Solution using Heroku Cloud and NodeJS Meteor Hooks
Heroku in particular is actually great for temporary file download links: they offer a "temporary scratchpad" filesystem that is reset every time the program restarts, and each running Node server cannot see the files other instances have created.
Each dyno gets its own ephemeral filesystem, with a fresh copy of the
most recently deployed code. During the dyno’s lifetime its running
processes can use the filesystem as a temporary scratchpad, but no
files that are written are visible to processes in any other dyno and
any files written will be discarded the moment the dyno is stopped or
restarted.
Taken from the Heroku documentation: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
Thus, any files written to the "filesystem" will be temporary.
This allows for a very easy solution to this problem: you can simply use NodeJS filesystem manipulation to create temporary files on the server, serve them once (or for a limited time), and then remove them so they cannot be downloaded again.
This in combination with something like $.download() will make a seamless experience which in turn prevents unauthorized downloads.
I am trying to get the database configuration functionality working with kohana 3.2. I want to attach the Config_Database as source:
Kohana::$config->attach(new Config_Database, False);
Described here: http://kohanaframework.org/3.2/guide/kohana/config
I attach the new source after loading the modules (so the database module is loaded before attaching the source). But when I have attached the new source it seems as if kohana does not want to load any controller using the Auth module with ORM driver. Then the browser loads and loads but only a white page appears. All other controller, not using the ORM or Auth module, function properly.
Can anyone give a short explanation how to use the Config_Database functionality, or give a alternative.
Update ORM module to 3.2/develop
I'm writing a node CRUD app that requires a few CouchDB views (I'm using express and cradle).
I've got the node app itself controlled with git, but my DB views are currently uncontrolled.
What's the recommended way to put these under source control? I don't want to put the entire database (including data) under source control.
Take a look at couchapp, http://couchapp.org/. You can use that to push your version-controlled design docs to a database.
Maybe useful: also CouchApp may push some docs in db. For example, doc(s) of configure or demo. For that put file in folder '_docs' (the same level with 'lists', 'shows', etc.) in JSON format.
File: 'any-configure.json'
{
"_id": "any-configure",
"fieldA": "...",
"fieldB": "...",
...
}
As pointed, using couchapp could make it easier to work with design documents.
I have implemented a similar approach in a Java project, an example here and the class that manages these documents.
Using YUI scripts on our SSL page turned out to break the SSL connection because they dynamically load scripts from yahoo (combo) over a http connection.
As we only use the history manager of YUI 3, I wanted to host the code on our server. If I copy the code from http://yui.yahooapis.com/combo?3.2.0/build/yui/yui-min.js&3.2.0/build/oop/oop-min.js&3.2.0/build/dom/dom-base-min.js&3.2.0/build/dom/selector-native-min.js&3.2.0/build/dom/selector-css2-min.js&3.2.0/build/event-custom/event-custom-min.js&3.2.0/build/event/event-base-min.js&3.2.0/build/node/node-base-min.js&3.2.0/build/event/event-synthetic-min.js&3.2.0/build/json/json-min.js&3.2.0/build/history/history-min.js&3.2.0/build/history/history-hash-ie-min.js It does not work anymore ("Y.History.getBookmarkedState is not a function" says firebug).
Does anyone know how to do that correctly?
Thanks
You're loading the modules correctly, but you're trying to use the deprecated History API (from YUI <=3.1.x). In YUI 3.2.0, the History Utility was rewritten, and the API is not backwards-compatible.
You can still use the old API in 3.2.0 by loading the history-deprecated module instead of history. Alternatively (and preferably) you can migrate to the new API, which is simpler and more flexible than the old one. You'll find a migration guide in the History Utility documentation.
I guess you should check the API. I've checked the code from this combo and it really loads History and submodules.
YUI({ bootstrap: false }).use('history', function(Y) {
Y.log(Y.History);
});
It shows outputs G(); Also I found getBookmarkedState declaration inside history-deprecated submodule so it seems like something new is used instead of this.