Showing posts with label translation. Show all posts
Showing posts with label translation. Show all posts

Sunday, August 20, 2017

how to translate using gettext on xampp server on OS X El Capitan version 10.11.6

Leave a Comment

I am working on a website that is using gettext for translation. The website is translating properly on servers of other machines but not on mine (OS X El Capitan version 10.11.6). I have follow the following tutorial to install gettext on mac:

link to the tutorial I followed

After the installation, gettext is not still working. Can someone help me here??

1 Answers

Answers 1

I followed pretty much the same instructions on Sierra (maybe you have messed up at some point?):

  1. Install the latest version of Xcode Command Line Tools. (by entering the following command in the terminal: xcode-select –install)
  2. Download the latest version of gettext and extract it to /Source or whatever you like.
  3. In the /Source director enter in the terminal: ./Configure, make, and sudo make install
  4. Download the PHP version that matches your system and extract it
  5. Change in the PHP source to the directory ext/gettext and enter the following commands: phpize, ./Configure, make, and sudo make install (each on a separate line). At this point you might get an SIP error, because the install has no access to /usr/libexec/php/extensions. However, the extension was created in the PHP source folder ext/gettext/modules
  6. Create a local extension folder: mkdir -p /usr/local/macoperator/lib/php/extensions and copy the newly created gettext.so extension to this folder
  7. Reference the local extension folder in your /etc/php.ini. Just add the following line at the end:

    extension_dir = "/usr/local/macoperator/lib/php/extensions" [gettext] extension=gettext.so

  8. Finally, make sure apache is restarted, by issuing:

    server-apachectl graceful

  9. Checking `phpinfo(), do you see:

    GetText Support enabled

Alternatively, you could try install PHP via Homebrew.

Read More

Saturday, February 18, 2017

How to fix “plural forms could be dangerous” django error?

Leave a Comment

I don't get it. If I set the Accept-Language header to anything other than "en" (de, pl, es) or even something that doesn't exist (like xxs), the app doesn't spit out this error, but it does when I set it to "en". It happens only on windows (newest gettext tools). Here's the stack trace:

Traceback (most recent call last):   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han dlers\exception.py", line 39, in inner     response = get_response(request)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han dlers\base.py", line 244, in _legacy_get_response     response = middleware_method(request)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\middlewa re\locale.py", line 29, in process_request     translation.activate(language)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\__init__.py", line 161, in activate     return _trans.activate(language)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\trans_real.py", line 238, in activate     _active.value = translation(language)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\trans_real.py", line 227, in translation     _translations[language] = DjangoTranslation(language)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\trans_real.py", line 129, in __init__     self._add_installed_apps_translations()   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\trans_real.py", line 176, in _add_installed_apps_translations     translation = self._new_gnu_trans(localedir)   File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr anslation\trans_real.py", line 156, in _new_gnu_trans     fallback=use_null_fallback)   File "C:\Python35\lib\gettext.py", line 426, in translation     t = _translations.setdefault(key, class_(fp))   File "C:\Python35\lib\gettext.py", line 162, in __init__     self._parse(fp)   File "C:\Python35\lib\gettext.py", line 297, in _parse     self.plural = c2py(plural)   File "C:\Python35\lib\gettext.py", line 76, in c2py     raise ValueError('plural forms expression could be dangerous') ValueError: plural forms expression could be dangerous 

I have plural-forms set up correctly in my django.po file:

"Plural-Forms: nplurals=2; plural=(n != 1);\n" 

Why does this happen and how to fix it?

3 Answers

Answers 1

I found an answer - the reason for that error is my incompetence :). I ran django-admin makemessages command in the root of my project, so next to _env and all the packages inside. This command created language files for a couple of projects with the default django.po file template, so they contained something like plural-forms=INTEGER and other stuff and this was causing the above error.

Answers 2

Your plural expression (n != 1) is most likely considered dangerous because it's too inclusive. n doesn't equal 1 means any value except 1 will evaluate to True including booleans, strings or None.

Try changing your expression to use equals, greater than and less than operations to narrow down the scope of the expression.

Answers 3

Here I will give you all the details about Plural-forms:

See this link Plural-forms.It will helps to you.

Note:This just link give a simple idea about plural

It surely helps to others

Read More

Friday, March 18, 2016

design from ltr to rtl automatically

Leave a Comment

I am a French website that is in LFR (Left to Right) And the client is wanting to translate the site in hebrew thus transforming it to RTL (Right to Left). In all Hebrew Website the design is reversed

https://he.wikipedia.org/wiki/

https://www.google.co.il/

Is there a way to do this automatically ? Again I am not talking about the text direction. I want to flip it horizontally the design, like a mirror effect.

1 Answers

Answers 1

Your mileage may vary. Some web page generation tools support RTL with easy switch, while with others the WYSIWYG breaks completely when you specify <html dir="rtl">. Browser fragmentation may also be an issue: some browser simply don't support RTL bulleted lists correctly.

There are quite a few good tutorials on the Web; I would recommend https://hacks.mozilla.org/2015/09/building-rtl-aware-web-apps-and-websites-part-1/ and https://hacks.mozilla.org/2015/10/building-rtl-aware-web-apps-websites-part-2/. If you look up Google to search for more articles, please remember that this field is quickly changing, and some recipes of few years ago may be obsolete.

You may find the automation with css-flip or rtlcss useful.

Note that localization is generally not easy, and invariably requires a manual touch. You must understand the target culture very well to recognize tiny glitches that may look awful to the end-user. For example, on Hebrew Website you need different image for the "back" button. On Arabic sites, some numbers should be represented by indic digits, but other numbers are expected to use the usual digits.

Issues of first day of week, etc. are common for LTR localizations, too.

Read More

Wednesday, March 9, 2016

Tool to organize translations in JSON files

1 comment

I'm investigating different translation tools for my Angular app. So far, angular-translate seems to be a good solution for that. It uses per-language JSON files that are structured like "lang/NAMESPACE/LANG.json" (e.g. "lang/user/de.json") and look like this:

{   "key1": "Value1",   "key2": "Value2",   "key3": "Value3",   } 

Optionally, the JSON might also be nested.

This seems to be easy to use. However, is slightly inconvenient when actually adding new or changing existing translations. You have to change back and forth different language files and it is cumbersome to find a translation for a certain key. Comparing different translations is also inconvenient.

Is there any tool that can read local translation files and is able to show different translations side-by-side for each key? Either an application (Mac OS support is a must) or browser-based.

2 Answers

Answers 1

Take a look at angular-translate: https://github.com/angular-translate/angular-translate

for all DIY folks:

You can find localized files for angular: here

These files will help you with the build-in angular filters: date, currency and number. Amazing... so far.

Now you want to use your own texts, than all you need is the power of angular.js dependency injection. Create a new file like: "myTexts_en_us.js" and use $provide.value like this:

$provide.value("myTexts", {firstText : "This is my localized text"}); 

For details: http://jsfiddle.net/4tRBY/24/

For real-world-use, you should add a filter: http://jsfiddle.net/4tRBY/41/

Tips:

  • Make sure to insert your new localization-file into your html by hand, JS or Server. (Server is the best choice here!)
  • if you include one of the angular-local files, you do not need to set it up in your app module. (you will have $locale automatically - see the fiddle)
  • add an id key to your $provide-value - and set the value to a language code you are using in your file - this will be come in handy for testing.

Answers 2

I needed the same thing myself and so I just wrote it like this:

I had 2 dropdowns with existing languages, from language 1 to language 2 was the idea.

on select both language I read the json files into arrays and displayed it with an ng-repeat using two way bindings so when the content of an input field changed, the array got updated instantly.

The apply method then uploaded the filename and the array towards a php file which wrote it to the document.

eng.json:

{   "ALBUM":{     "TITEL":"album",     "LAAD_MEER":"Load more",     "ALBUMS":"Back to albums"   },   "INFO":{     "TITEL":"information",     "HOTELS":"Hotels",     "SPORTHAL":"Sportscenter",     "INTHISHOTEL":"In this facility"   } } 

my html:

<section ng-if="toSelected"          class="bg-g-r bg-u-1 card flyin"          ng-repeat="section in fromContents"          id="{{'trans'+section.TITEL}}"          class="translatorSection">      <p class="paddedText bg-u-1 blueElement">{{section.TITEL}}</p>     <div class="textContainer bg-u-1"          ng-repeat="line in section">         <p style="color:grey">{{line}}</p>         <textarea class="bg-u-1" ng-model="toContents[getKeys(toContents,$parent.$index)][getKeys(section,$index)]"                 style="padding: 8px;border-radius: 10px"                 ></textarea>     </div> </section> 

my controller:

//Bound to the dropdowns in my case $scope.fromSelected = null; //language from wich to start $scope.toSelected = null; //language i wish to extend  $scope.fromContents = null; $scope.toContents = null;  $scope.$watch('fromSelected', function (abbr) {     if(abbr) {         jsonFactory.getLanguageContents(abbr).then(function (data) {             $scope.fromContents = data.data;         });     } }); $scope.$watch('toSelected', function (abbr) {     if(abbr) {         jsonFactory.getLanguageContents(abbr).then(function(data){             $scope.toContents = data.data;         });     } });  $scope.getKeys = function (array,index){     return Object.keys(array)[index]; };  $scope.getToValueByKey = function (key){     return $scope.toContents[key]; };  $scope.apply = function (){                 jsonFactory.UploadLanguage($scope.toSelected,$scope.toContents)         .then(function(data){             alert('update succesfull, please reload')         }); }; 

Jsonfactory:

    function getLanguageContents(lang) {         var deferred = $q.defer(),             httpPromise = $http.get('languages/'+lang+'.json');          httpPromise.then(function (response) {             deferred.resolve(response);         }, function (error) {             console.error(error);         });          return deferred.promise;     }         function UploadLanguage(lang,content){             return $q(function(resolve,reject){                 var xmlhttp,                     params = 'lang='+lang+'&content='+JSON.stringify(content);                  if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari                     xmlhttp = new XMLHttpRequest();                 }                 else { // code for IE6, IE5                     xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');                 }                  xmlhttp.open('POST', 'http://localhost:63342/website/app/php/translator.php', true);                 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');                 xmlhttp.onreadystatechange = function() {                     if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {                         var data = xmlhttp.responseText;                         resolve(data);                     }else if (xmlhttp.readyState === 4){                         reject('not found');                     }                 };                 xmlhttp.send(params);             });         } 

Read you folder with json files in javascript into some arrays, For each array just create an ng-repeat using input fields so you see the key and all you translations with it, when you made changes create a button that sends you array and the language filename to this php script: (i only accept one language at the time)

<?php   header("Access-Control-Allow-Origin: *");   $taal = $_POST["lang"];   $content = $_POST["content"];   $myfile = fopen("../languages/".$taal.".json", "w");   fwrite($myfile, $content);   fclose($myfile);   echo $taal;   echo $content; ?> 

It was actually very easy to create, I wanted to add it to my site, so everyone could help translating but it never got there.

I cant give all the code, but i thik this should get you started.

Read More