Cakephp 3 Localization issue - cakephp

I'm using the localization feature to translate my app in French, but I'm running into some constraints I was not expecting.
In the default.po file, when I set:
msgid "MainLoginAccountLocked"
msgstr "Votre compte a été verrouillé."
It works fine. I can see the message translated.
But when I set:
msgid "Main Login Account Locked"
msgstr "Votre compte a été verrouillé."
It's not working. I get the "Main Login Account Locked" key instead of the translation.
Is there limitations in the msgid values? Or restricted values?
I've found nothing in the doc that could help me.

There are no limitations of having spaces in the msgid, I use it all the time.
#Nds's advice is pertinent: clear your cache.
In the past I also ran with problem on the compiles version of the .po file that needed to be regenerated.
Carefully verify the spaces at the end and beginning of the string.
Maybe also you should verify the encodings involved. If you are using UTF-8 everywhere (as I hope), it shouldn't be the issue.

Related

CakePHP Localization of static data

CakePHP Version: 3.6.6
I apologise in advance for such a long post but I believe this is all the information needed for someone to be able to help.
===========================================================================
SECTION 1
// WHAT I'D LIKE' TO ACHIEVE
Ultimately I'd like my application to automatically detect the language of the user and change the following accordingly:
Text.
Date format.
Number format.
Currency.
In an effort to realise this I started by simplifying it by not attempting to automatically detect the language of the user but manually changing the locale in config/app.php.
===========================================================================
SECTION 2
// THE INFORMATION I'VE REFERENCED
Internationalization & Localization - Here
I18N Shell - Here
===========================================================================
SECTION 3
// WHAT I HAVE BEFORE I START
config/app.php
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_GB'),
config/bootstrap.php
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
// Welcome controller
?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Event\Event;
// For translation
use Cake\I18n\I18n;
use Cake\I18n\Time;
use Cake\I18n\Number;
class WelcomeController extends AppController
{
public function index()
{
// Get the default locale
$defaultLocale = I18n::getDefaultLocale();
echo $defaultLocale . '<br />';
// Date
$date = new Time('2017-12-05 23:00:00');
echo $date . '<br />';
// Number
echo Number::format(123.50) . '<br />';
// Currency
echo Number::currency(1250.00) . '<br /><br />';
}
}
// index.ctp
<?= __('Welcome') ?>
<br />
<?= __('What would you like to do today!') ?>
// This is what the browser displays
en_GB
05/12/2017, 23:00
123.5
£1,250.00
Welcome
What would you like to do today!
===========================================================================
SECTION 4
// WHAT I'VE DONE
1. Created a folder in src named Locale
2. Created a folder in Locale named de_DE
3. Navigated to the bin with the cli.
4. Typed cake i18n extract and clicked enter.
5. After clicking enter the following is displayed by the cli:
Current paths: None
What is the path you would like to extract?
[Q]uit [D]one
[C:xampp\htdocs\app_name\src] >
I then add the following after > and click enter
C:xampp\htdocs\app_name\src\Template\Welcome
6. After clicking enter the following is displayed by the cli:
Current paths: C:xampp\htdocs\app_name\src\Template\Welcome
What is the path you would like to extract?
[Q]uit [D]one
[D] >
7. I then click enter and the following is displayed by the cli:
Would you like to extract the messages from the CakePHP core? (y/n)
[n] >
8. I then click enter and the following is displayed by the cli:
What is the path you would like to output?
[Q]uit
[C:xampp\htdocs\app_name\src\Template\Welcome\Locale] >
I then add the following after > and click enter
C:xampp\htdocs\app_name\src\Locale
9. I then click enter and the following is displayed by the cli:
Would you like to merge all domain strings into the default.pot file? (y/n)
[n] >
10. I then click enter and the following is displayed by the cli:
Extracting...
Paths: C:xampp\htdocs\app_name\src\Template\Welcome
Output Directory: C:xampp\htdocs\app_name\src\Locale\
====================================================================> 100%
Done.
11. After this I have a default.pot file in the src/Locale folder. I copy and paste this file into the de_DE folder.
The contents of this folder are as below:
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL#ADDRESS>
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2018-09-05 09:20+0000\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL#ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL#ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: Template/Welcome/index.ctp:52
msgid "Welcome"
msgstr ""
#: Template/Welcome/index.ctp:58
msgid "What would you like to do today!"
msgstr ""
I then add the following into the 2 msgstr so they look like the below:
#: Template/Welcome/index.ctp:52
msgid "Welcome"
msgstr "abc"
#: Template/Welcome/index.ctp:58
msgid "What would you like to do today!"
msgstr "xyz"
I then change the default locale in config/app.php to:
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'de_DE'),
I then refresh the browser and the below is displayed:
de_DE
05.12.15, 23:00
123,5
1.250,00 €
Welcome
What would you like to do today!
===========================================================================
SECTION 5
// RESULT
The locale, date, number and currency have changed but NOT the text. It still displays:
Welcome
What would you like to do today!
And I was expecting it to display:
abc
xyz
===========================================================================
SECTION 6
// WHAT I'VE TRIED TO FIX IT
I added the below to the middleware - Application.php:
// Add middleware and set the valid locales
$middlewareQueue->add(new LocaleSelectorMiddleware(['en_GB', 'de_DE']));
And this is what the browser displayed:
de_DE
05/12/2015, 23:00
123.5
£1,250.00
Welcome
What would you like to do today!
The locale is still de_DE but the date, number and currency have reverted back to English?
===========================================================================
SECTION 7
// SUMMARY
I'd really appreciate any help on this because it would be brilliant if I could get my application localized and have the functionality of allowing a user to use my application in their native language. I'm really restricting my market if I can't get this working.
If there's anything else that I haven't written but you need please don't hesitate to let me know.
Many thanks in advance for any help. Z.
===========================================================================
#ndm - Thanks for the response, learnt a lot already but still no cigar.
I downloaded Poedit and opened it. I then clicked on "Edit a translation" and opened default.pot file from the Locale folder.
Everything looks good and the below is displayed:
Welcome
What would you like to do today!
I then click on 'Create new translation' and select German from the dropdown, the window is divided into 2 halves:
On the left - Source text - English.
On the right - Translation - German.
I highlight 'Welcome' and select the German equivalent 'Willkommen' which is then populated in the right window. I do the same for 'What would you like to do today'.
At this point the right window is populated with the German equivalents so I go to Save as and save the file in my de_DE folder in the src/Locale folder.
My de_DE folder is now populated with 2 files as detailed below:
de.mo
de.po
I open the de.po file and the contents are detailed below:
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL#ADDRESS>
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2018-09-05 09:41+0000\n"
"PO-Revision-Date: 2018-09-05 14:26+0100\n"
"Language-Team: LANGUAGE <EMAIL#ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.1.1\n"
"Last-Translator: \n"
"Language: de\n"
#: Template/Welcome/index.ctp:52
msgid "Welcome"
msgstr "Willkommen"
#: Template/Welcome/index.ctp:58
msgid "What would you like to do today!"
msgstr "Was würden Sie heute gerne machen!"
I then clear the cache (tmp/cache/persistent) and refresh the browser.
To confirm I have the below in config/app.php
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'de_DE'),
And I have commented out the middleware reference.
Unfortunately the text has still not been translated?
It seemed like a relatively straight forward process so I'm surprised it hasn't worked. I'm hoping you can see something that I've done incorrectly in the process I've used as documented above.
Thanks again, Z.
// WHAT I'VE TRIED AS A FIX
1. I've tried changing the language definition in config/app.php from:
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'de_DE'),
to
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'de'),
then cleared the cache and refreshed but no luck.
2. I reversed the above then tried changing the language definition in the de.po file from:
"Language: de\n" to de_DE\n
then cleared the cache and refreshed but still no luck.
.pot files are templates (in PO format), you use them to create the final translation files in .po (plain) or .mo (binary) format from them (these are the files that CakePHP is looking for), or to update the latter with changed messages.
You can rename and edit the files manually, or use tools like Poedit that provide a GUI for the gettext tools which can help you with creating/updating .po/.mo files.
Whenever making changes to translation files, remember to clear the cache (tmp/cache/persistent) afterwards!
I know this is a bit late, but for anyone who stumbles across this tread.
Check the permissions of the src/Locale, src/Locale/de_DE and .po &.mo files.
I had a similar issue that the .po and .mo files I had generated were not readable by the web server user, and the translations of text failed silently, as appears to be the case in the OPs question.

Solr highlightning distinction

When I look for the word "Unternehmen" with the following query
q="Unternehmen"&
hl=true&
hl.simple.pre=<em>&
hl.simple.post=</em>
I get this Result if the Word Unternehmen is found twice within a close distance within the same field:
Um als <em>Unternehmen die Zukunft erfolgreich zu gestalten, brauchen Unternehmen</em> Innovationen
When "Unternehmen" is found within the same field not within close distance solr gives me:
olle in <em>Unternehmen</em>, hat eine lange Tradition in der Betriebswirtschaftslehre. Dieses Special Issue widmet sich in vielfältiger Weise dem Thema der geeigneten Corporate Governance in mittelständischen oder öffentlichen deutschen <em> Unternehmen </em>. ​
How do I prevent solr from merging highlighting when the matches are too close? I always want to get the second variation of highlighting.
I already tried playing around with hl.fragsize= 0, 10,1000, hl.snippets=2 with no visible effect.
I tried your example in Solr 5 here using the standard /select Request Handler, and highlighting worked as expected (your second variation) on the first sentence.
Try the following:
What field type do you have for the field where you are querying and highlighting text in? Even if it is German, try "text_en" as the field type and re-index the document for testing.
Try querying and highlighting not on the general catch-all field, but specifically on the field (lets assume it is "mytext") you have your text, such as:
q=mytext:"Unternehmen"&hl=true&hl.fl=mytext&hl.simple.pre=<em>&hl.simple.post=</em>

CakePHP 2: Localization&Internalization for function timeAgoInWords()

My problem is that I can not translate a date from English to Russian.
I followed this guides:
Internationalization & Localization CakePHP
I18N shell
I wrote in AppController.php this code:
function beforeFilter() {
parent::beforeFilter();
setlocale(LC_ALL, "ru_RU.utf8");
Configure::write('Config.language', 'rus');
CakeSession::write('Config.language', 'rus');
}
I added a folder "Locale\rus\LC_MESSAGES" and place inside the file default.po.
BTW i extracted all messages to the single file.
But in fact:
<?php echo $this->Time->timeAgoInWords($feedback['Feedback']['created']); ?>
Did nothing.
<?php echo __d('default', $this->Time->timeAgoInWords($feedback['Feedback']['created']), true); ?>
Translates only string 'just now' to russian language, but other time formats still in English.
Examples of translates from default.po you can see below:
success
#: Lib\Cake\Utility\CakeTime.php:842
#: Utility\CakeTime.php:842
msgid "just now"
msgstr "translate"
fail
#: Lib\Cake\Utility\CakeTime.php:829
#: Utility\CakeTime.php:829
msgid "%d week"
msgid_plural "%d weeks"
msgstr[0] "%d translate"
msgstr[1] "%d translate"
I can't understand what i'm doing wrong.
For translating CakePHP core strings like those in Lib\Cake\Utility folder you need to use a different translation domain. The default domain for your views would be 'default' but for CakePHP core strings it is 'cake'.
Instead of 'default.po' you need to provide 'cake.po'. Otherwise your translations will have no effect.

How to understand log files downloaded from App Engine?

What is the format of Google App Engine log files, as downloaded by appcfg.sh request_logs?
As far as I've been able to determine, the format of the log file is as follows:
CLIENT_IP_ADDRESS - USERNAME [DATE:TIME TIMEZONE] "METHOD URL HTTP/VERSION" RESPONSE_CODE ??? URL USER_AGENT
LOG_LEVEL:TIMESTAMP MESSAGE
:
LOG_LEVEL:TIMESTAMP MESSAGE
:
LOG_LEVEL:TIMESTAMP MESSAGE
:
Each of the indented lines is associated with the non-indented line above it - that's how you determine which request each of them relates to, I think. The solitary colons are used to separate one log message from the next.
The non-indented lines are in reverse chronological order, but the groups of indented lines below them are in chronological order.
A strange client IP address like 0.1.0.2 indicates a within-App-Engine post from your app to your app's task queue. Actually, though, you can also see that it is within-App-Engine by looking at the user agent for that request.

Apple iWork Mime Types

I was wondering what the mime type for iWork's Pages is? And also what the mime type is for the rest of the software in the iWork suite? I looked around online and I didn't see it anywhere.
I recently needed this for work and ended up just uploading some files and querying the mimetypes. I found the following:
keynote: application/x-iwork-keynote-sffkey
pages: application/x-iwork-pages-sffpages
numbers: application/x-iwork-numbers-sffnumbers
2021 Update
Please note that this answer is now outdated and the following content types have been approved by IANA:
application/vnd.apple.pages
application/vnd.apple.keynote
application/vnd.apple.numbers
Looks like Apple doesn't much care, since installing iWork does not add any mime type information to any of its system mime-type info reps (in /etc/cups and /etc/apache2), "Get Info" on an iWork file shows no mime-type, etc. The only hint I've found is in Page's info.plist (a copy's online here) which mentions:
<key>public.filename-extension</key>
<array>
<string>pages</string>
</array>
<key>public.mime-type</key>
<array>
<string>application/x-iwork-pages-sffpages</string>
</array>
and a similar one for filename-extension "template", with "-sfftemplate" as the suffix instead of "-sffpages".
application/vnd.apple.keynote
application/vnd.apple.pages
application/vnd.apple.numbers
Just got it approved with IANA. You will find the list at the below link.
https://www.iana.org/assignments/media-types/media-types.xhtml.
You can use mime-db https://github.com/jshttp/mime-db to validate using javascript
This URL shows some other types in case new readers need it:
Apache Jira Issue TIKA-588
application/vnd.apple.keynote, application/vnd.apple.pages, application/vnd.apple.numbers
Actually, those files are all a masked zipfile. So, some systems might indicate their mimetype simply as application/zip.

Resources