Localizing timeAgoInWords in CakePHP - cakephp

In my CakePHP application,
By using cake.bat i created POT files and by using PoEdit I created PO files.
So by writing __('myword') i can see localized word in my application successfully.
But now I need to localize "timeAgoInWords".
When i run cake i18n extract, script didn't get the _dn() words in CakeTime
http://api20.cakephp.org/view_source/cake-time#line-522
So i created a dummy.ctp file and copy-pasted contents from cake-time file to dummy file.
I run cake script and POEdit again. And it created instances like below, into the file app/Locale/tur/LC_MESSAGES/default.po
#: View\App\dummy.ctp:30;33
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] "%d dakika"
msgstr[1] "%d dakika"
In core.php i already set default language to Turkish:
Configure::write('Config.language', 'tur');
But when i check my application, results of timeAgoInWords came in English.
How can i fix this

Cake's messages are extracted into a different domain, in this case, the cake domain. This means that cake messages will not be extracted into your default.pot file, but will go into cake.pot file.
Curiously, cake.pot doesn't seem to be included in the download, nor does the i18n shell allow you to pass a param to include the cake core during extraction. However, it is still easily done (my comments start with a #):
$:/var/www/path/app$ cake i18n extract
# if will ask you here if you want to extract from your app folder
# simply press enter to confirm
What is the path you would like to extract?
[Q]uit [D]one
[/var/www/path/app/]
# now it will ask you again, in this case enter the cake path
What is the path you would like to extract?
[Q]uit [D]one
[D] > /var/www/path/lib/Cake
# third time, just press enter
What is the path you would like to extract?
[Q]uit [D]one
[D] >
# press enter to accept the app/Locale
What is the path you would like to output?
[Q]uit
[/var/www/path/app//Locale] >
# press enter to keep translation domains deparate
Would you like to merge all domains strings into the default.pot file? (y/n)
[n] >
Now wait for the extraction to finish and enjoy the pain of translating ;)

Related

Cakephp 3 i18n not working

I have cake 3 fresh installation.
I have a simple po file in this location src/Locale/de_DE/default.po with the following content.
msgid "test"
msgstr "test in german"
On my home page template file I have simple <?php echo __('test'); ?>
I need to set the locale on the fly, so I add this to my AppController's beforeFilter(or initialize) - I18n::locale('de_DE'); however test is not being translated. I can't figure out, what Im missing. I tried renaming all to iso2 - de, but it did not translate either.
Thanks
Open your Terminal, cd to your project folder (the one which contains the bin folder) and type:
bin/cake cache clear_all
That's all. Refresh your page right after.
One last thing, be sure to place your .po files in:
Locale/de_DE/your_translations.po
I like to use POEdit to manage my translations. Cheers.
Maybe this helps:
If you are working on a local maschine and use bin/cake i18nto generate the translation files, make sure the files are readable by your local webspace.
This drove me cracy.

Cakephp 3 : Unable to apply Localization in a simple text.

I am following this doc to learn localization basic. I have followed below step
I have an index.ctp file here I have added a headline
<h2><?= __('Popular Articles') ?></h2>
Now for .pot file I have used below command
bin/cake i18n extract
default.pot file generate well then I have moved this file to
src\Locale\jp\default.pot
Here I have found below line in default.pot
#: Template/Tests/index.ctp:1
msgid "Popular Articles"
msgstr ""
I have added msgstr "人気の記事"
Now in config/bootstrap.php I have added below code to make default language jp
ini_set('intl.default_locale', 'jp');
Still it's giving me same output.
change the file name as default.po
change the folder name as ja_JP
and also ini_set('intl.default_locale', 'ja_JP');
Translation folders can either be the two letter ISO code of the language or the full locale name such as fr_FR, es_AR, da_DK which contains both the language.
more info: http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#language-files

Can not open downloaded PDF files

I'm trying to download needed PDFs related to a researcher.
But the downloaded PDFs can't be opened, saying that the files may be damaged or in wrong format. While another URL used in test resulted in normal PDF files. Do you have any suggestion?
import requests
from bs4 import BeautifulSoup
def download_file(url, index):
local_filename = index+"-"+url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
return local_filename
# For Test: http://ww0.java4.datastructures.net/handouts/
# Can't open: http://flyingv.ucsd.edu/smoura/publications.html
root_link="http://ecal.berkeley.edu/publications.html#journals"
r=requests.get(root_link)
if r.status_code==200:
soup=BeautifulSoup(r.text)
# print soup.prettify()
index=1
for link in soup.find_all('a'):
new_link=root_link+link.get('href')
if new_link.endswith(".pdf"):
file_path=download_file(new_link,str(index))
print "downloading:"+new_link+" -> "+file_path
index+=1
print "all download finished"
else:
print "errors occur."
Your code has a comment saying:
# Can't open: http://flyingv.ucsd.edu/smoura/publications.html
Looks like what you can't open is a HTML file. So no wonder that a PDF reader will complain about it...
For any real PDF link that I had a problem with I would proceed as follows:
Download file with a different method (wget, curl, a browser, ...).
Can you download it even? Or is there some password hoop to be jumped through?
Is the download fast + complete?
Does it then open in a PDF viewer?
If so, compare to the file your script downloaded.
What are the differences?
Could they be caused by your script?
Are there no differences within the first few hundred lines, but differences later? End of the file being a bunch of nul-bytes? Then your download didn't complete...
If not so, still compare the differences. If there are none, your script is not at fault. The PDF may really be corrupted...
What does it look like, when opened in a text editor?

How to remove specific characters from a file name?

I have bunch of files that need to have a (.) dot removed from the file-name. Eg. "Mr.-John-Smith.jpg" to "Mr-John-Smith.jpg". I don't have real experience with programming and know only html/css and a little javascript. I found another identical question here on stackoverflow, but what I gathered it was fixed on linux system and BASH was used.
Anyways, if anyone could provide me a tutorial on which program to use for this and what code to execute in that program to make it happen I'd be grateful.
if you are using a windows environment (which i guess you do)
you can download this free utility to mass change file names !
main page :
http://www.bulkrenameutility.co.uk/Main_Intro.php
download page :
http://www.bulkrenameutility.co.uk/Download.php
its easy to use
enjoy
If your file names in a file...
1- Open Microsoft Word or any text editor. Press ctrl+h and then search "." without quotes then replace it with blank character.
2- It will remove all dots, again bring "." to your file extention such as .jpg , .png searh your file extention for example "jpg" and replace it with ".jpg"
It will works %100, i am using this method everytime.
if they are not in a file and if you want do somethings in your operation systems' file system
Try this program. It is very useful for this operation;
Download
To remove all except the extension dot from all files in a directory, you can use PowerShell that comes with newer versions of Windows, and can be downloaded for older versions;
Line breaks inserted for readability, this should go on one line;
PS> dir | rename-item -newname {
[System.IO.Path]::GetFileNameWithoutExtension($_.name).Replace(".","") +
[System.IO.Path]::GetExtension($_.name); }
What it does is to take the file name without an extension and remove all dots in it, and then add back the extension. It then renames the file to the resulting name.
This will change for example do.it.now to doit.now, or in your case, Mr.-John-Smith.jpg to Mr-John-Smith.jpg.

remove file path in terminal and just display a folder

So to get started with my work I usually have to cd into a specific folder in iterm2.
Sorta looks like this [johnson#david-MacBook-Pro /Applications/MAMP/htdocs/demoapp] 16:41:32 $
As you can see that takes up a ton of room in the damn window. How do I remove the name of the path and just have it so its like this
demoapp ->
I've seen this in video tutorials where the only thing on the screen is the name of the folder or directory the person is in without all the extra info.
Obviously this a Mac specific question. Is it possible to toggle between showing full path and just specific path for quick reference?
thanks!
When one uses a Terminal (in Linux or Mac) initiated as root, only the actual directory is shown. In my case (using Linux Mint), if I start a normal Terminal, and use the command su to login as root, the complete path changes to the actual directory.
Try this:
a) write su on the Terminal
b) enter...
c) it asks for the root password, write it and press enter again.

Resources