Dynamic create translations file. Angular translation - angularjs

I'm in need of a way to dynamically create my translations file for my app.
Right now i can create the json object like this, in my app
{
Name: 'User Name',
}
but i can't find a way to tell my $translateProvider to use this to translate my site, Do anyone know how this can be done?

Use angular-gettext translator
angular-gettext.rocketeer.be

Related

.dot template and angular or what should I use here?

This is a generic question don't need the "ready to use" code , but an idea where should invest my time in. I set mustache tag because may be similar.
This is an express (4) application using .doT template where i want to expand with some angular (1.4.3) features.
Doesn't seem possible to me to work with .doT template and angularjs , I'm i right here? .I'm trying get it to work a .html template file and his angular application without success( return a 404 cause don't find a template, but when i use with ejs, it does work ( because it read .html files)
2 . STILL , would like to know in case i'm wrong above. considering this anwer that state is possible to use multiple view engine with consolidate. is possible and how would it be done with angular? (just a hint, doens't need to be the whole implementation)
I know by this answer would be possible to use this below, but also says is better to use a helper, is possible to use helpers in.doT template ? , how?
appModule.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
considering the above. Which one of 2 and 3 whould you say would be faster?
it would considerably be faster if I change my app to ejs view engine ?
Point by point :
This is incorrect , .doT template works well with Angular, I have use it both, as long as you render a route with dot.
router.get("/blog/new", function(req, res) {
res.render("owner/blog/create");
});
and set a state in your angular provider like
$stateProvider
...
.state("owner-new-blog", {
url: "/blog/new",
templateUrl: "/owner/blog/new",
controller: "CreateUpdateCtrl"
})
There is no point to use consolidate middleware, .doT template works with angular template out of the box, unless you change .doT default parameters.
Yes ... that would be like this , like state in this post
var dT = require('doT');
var tpl = {
tmpl:dT.template('{{=this.helper()}}'),
helper: function(){
/* do what you want to do */
}
}
tpl.tmpl(); // render template
as you can see in this benchmark , .doT is pretty fast if you set double engine in you app , is a bit slowe since you are expanded is functionallity, if you set a helper in doT is less painfull than having two engines .. so , is faster adding a Helper to dot.
there is no point in changing to ejs , dot is pretty fast and an advance template engines which suport layouts and partials. and still , in my opinion, is faster.

AngularJS - parameters in css files

I'm currently migrating from custom framework to Angular. Since we've got legacy, all front-end resources like stylescheets, images and scripts should be located on a subdomain, and all urls should be absolute. I've got a bunch of css files with a parameter specifying our static domain. I'm looking for a native Angular approach to using parameters in css, so I'll be able to write smth like:
.body {background: "{{domain}}/img/bg.png";}
Currently in our framework styles are loaded with, say, $http.get(), then processed with .replace and then appended to DOM.
Any ideas?
Thank you.
Try the $interpolate service. Inject it in a method, then use like this:
var fn = $interpolate(cssText);
var processedCssText = fn(scope); // scope is whatever obj that contains `domain` and other properties that might be used inside cssText
You can even configure the opening & closing symbols, if needed. See the documentation for $interpolate for more information.
You want LESS.
http://lesscss.org
It's the "dynamic stylesheet language".

extjs 4 and translation

I'm coding with extjs 4. I want to provide two language buttons for the French language and English language. I have googled the problem, but I didn't find a solution. I hope I will find a solution here.
You can place your translations (for example as overrides) in different files and load them according to the language. You can see an example here:
http://docs.sencha.com/ext-js/4-0/#!/example/locale/multi-lang.html
Sencha introduced the following approach:
Keep translatable-text in separate configs:
Ext.define('MyForm',
extend: 'Ext.form.Panel',
// the next config is translatable
submitBtnText: 'Submit',
// ...
Create another js file which overrides locale configs and include it (js file) in html page:
// MyForm-fr.js
Ext.define('MyFormFr', {
override: 'MyForm',
submitBtnText: 'soumettre'
});
Take a look at Sencha's official example.
I have token a look at the Sencha's official example, but now I want to add the translation to my application. In the example that I have followed the files.js and the file.html are in the same directory, but my application follows the MVC architecture, so it differs.
I have a js file that contains words to translate:
if (Ext.app.ContactForm) {
Ext.apply(Ext.app.ContactForm.prototype, {
formTitle: 'Contact Informatie (Dutch)',
firstName: 'Nom',
lastName: 'Prénom'
});
}
And my application contains just one file.html, so I don't know where to put the file.js, in the same directory of the file.html or in the view folder! And how it can be readable bye all the application

Drupal: embed contact form from contact module directly into template (rather then as a stand alone "page")

Full disclosure; I'm a complete newbie to Drupal development.
I've been tasked with embedding a contact form in the footer component of our site's template. I've been told to use the Drupal Contact module for this task. The problem is, I don't see how this is possible without dramatically altering the contact module itself. Is there any way to embed the Drupal Contact Module's form in a template; rather than have it as a standalone page? Any constructive input is greatly appreciated.
I'd also be open to any other way of embedding a form directly in a Drupal template.
Thanks, Frank
You should be able to accomplish that by adding the following code into your theme's template.php file:
function mytheme_preprocess_page(&$variables) {
module_load_include('inc', 'contact', 'contact.pages');
$variables['contact_form'] = drupal_get_form('contact_site_form');
}
Then in your page template file(s) you can output it with the following code snippet:
<?php print render($contact_form); ?>
Don't forget to replace 'mytheme' with your actual theme's name and clear the caches.
Frank,
The following worked for me, I placed it directly in my template.
require_once drupal_get_path('module', 'contact') .'/contact.pages.inc';
print drupal_render(drupal_get_form('contact_site_form'));
source

Simple examples on how to use CakePHP pages_controller.php to create static pages

I am complete beginner to CakePHP but I am a bit knowledgeable in ROR.
Can somebody pls give me some simple examples on how to make use of pages_controller.php? I want to create static pages such as Home, About, and etc but I don't know how and where to start. I tried something like creating a about.ctp in the views and creating about_controller.php (this is how being done in Ruby on Rails) but I just got some errors.
I concluded that all of the static pages will only use 1 controller which is pages_controller.php but I dont know how.
I tried reading the article found on this link:
http://book.cakephp.org/view/958/The-Pages-Controller
but it doesn't give me anything that will help me learn how to use it.
This is what I got from the page:
CakePHP core ships with a default controller called the Pages Controller (cake/libs/controller/pages_controller.php). The home page you see after installation is generated using this controller. It is generally used to serve static pages. Eg. If you make a view file app/views/pages/about_us.ctp you can access it using url http://example.com/pages/about_us
When you "bake" an app using CakePHP's console utility the pages controller is copied to your app/controllers/ folder and you can modify it to your needs if required. Or you could just copy the pages_controller.php from core to your app.
Can somebody pls show me or explain to me how??? I am a total beginner pls help.
It's pretty self explanatory.
Create a file in your APP/views/pages/ folder - e.g about_us.ctp
Type in your content. No layout; just the text, tables/images/etc
<h3>About my site</h3>
<p>bla bla la</p>
<?php echo $this->Html->image('my_img.jpg'); ?>
Save.
Go to www.site.com/pages/about_us - your page is served.
Pages is the controller to serve static pages. you don't need an about_controller, unless you need something more than just a static page.
You can change how the link looks by using routing.
You can set variables for use in your template as well:
about_us.ctp
<?php
$this->set('title_for_layout', 'My about page');
$this->set('active_link', 'about');
?>
<h1>My page!</h1>
etc

Resources