Wednesday, 29 July 2015

AngularJS and localisation/internationalisation with angular-translate

I have just battled to get translation working. I was trying to follow http://www.ng-newsletter.com/posts/angular-translate.html which seems ok. However there were multiple issues along the way, so I thought I would detail them here.

Initial Setup

Just add the following as a dependency to the angular app

 'pascalprecht.translate'

You will also need to include a reference to angular-translate.min.js.

Sanitize

When you run the app, the library shows a warning that you should set a sanitise option. To do this, you need to add another dependency to the angular app

 'ngSanitize'

You will also need to include a reference to angular-santize.min.js if you don't already have one.

You then need to add this line to configure the strategy

 $translateProvider.useSanitizeValueStrategy('sanitize');

Async page load

For async page loads, you need to add a reference to angular-translate-loader-static-files.min.js. You can use this config

 $translateProvider.useStaticFilesLoader({
    prefix: 'i18n/locale-',
    suffix: '.json'
 });

Error On Load

I followed the samples, and when the async load occurred, the async load/parse failed with the following error.

 Unexpected token '

The secret is to make sure both keys and values are enclosed in quotes.

 {
   "TITLE": "Hallo",
   "FOO": "Dies ist ein Paragraph.",
   "BUTTON_LANG_EN": "englisch",
   "BUTTON_LANG_DE": "deutsch"
 }

JSON requires this. I did find someone else that hit the same problem, so I guess it is not just me.

Stopping Page Flicker

When you load the translations async, the page first shows with the keys, and then updates to show the actual translations. If you search, everyone says "just use translate-cloak". They neglect to actually tell you how.

Body Tag

I added the translate-cloak directive to my body. I also added the translate-cloak css class. The directive ensures that the class is removed when the page has loaded. The css means that as the page loads, it is initially hidden

 translate-cloak class="translate-cloak"

CSS

I couldn't find anyone mention it, but you actually need to hide the css style translate-cloak. So I added the following to the css

 .translate-cloak {
    visibility: hidden;
 }

Wednesday, 3 June 2015

How to setup The Bug Genie v4.0.0 (thebuggenie) on Ubuntu using virtualbox virtual machine

Download Virtualbox and ubuntu 14.04.2. Install ubuntu into a fresh virtual machine. Then follow the following steps to setup thebuggenie.

Apache


 sudo apt-get install apache2 libapache2-mod-php5 
 a2enmod rewrite

thebugggenie


 wget https://github.com/thebuggenie/thebuggenie/archive/v4.0.0.tar.gz
 tar -xvzf v4.0.0.tar.gz 
 cd thebuggenie-4.0.0/

 sudo mv * /var/www/html
 sudo mkdir /var/www/html/files
 sudo chown -R www-data:www-data /var/www/html

To enable .htaccess overrides, open this file

 sudo nano /etc/apache2/sites-available/000-default.conf 

Search for this line

        DocumentRoot /var/www/html

And add these 3

        <Directory "/var/www/html">
            AllowOverride All
        </Directory>

service apache2 restart

MySql


sudo apt-get install mysql-server

Next you need to setup a user and a database. To do this, enter the following commands

  • Connect to mysql with mysql -u root -p
  • Create the database with CREATE DATABASE thebuggenie;
  • Create the user with CREATE USER thebuggenie@localhost IDENTIFIED BY 'password';
  • Grant privileges with GRANT ALL ON thebuggenie.* TO thebuggenie;
  • Flush privileges with FLUSH PRIVILEGES;
  • Logout from root - quit
  • Then test you can connect using mysql -u thebuggenie -p, and then enter the password. If you can connect successfully, then quit and continue


PHP


sudo apt-get install php5-cli php5-gd php5-curl php5-mysql git 

Composer and thebuggenie setup

curl -sS https://getcomposer.org/installer | php

php composer.phar install

Then access http:///public/index.php

nano /etc/php5/apache2/php.ini

add to end of file

extension=mysql.so
extension=imap.so

service apache2 restart