I'm developing an app from the yii2-advanced-app.
In a controller (DocumentController) I read out files in a directory with the FileHelper::findFiles().
It's working, but if my filename contains non-ASCII characters (like the German umlauts, äöü) I only get a question mark in the returning file-path.
How do I solve this? I can't find a suitable answer.
As the web server I'm using IIS 7 on a Windows Server 2008 R2 Enterprise.
DocumentController.php
use yii\helpers\FileHelper;
$data = FileHelper::findFiles($folderPath,['except'=>['*.db']]);
var_dump($data);
The result is:
array(1) { [0]=> string(84) "C:\Websites\dev.point-s.de\space/space_attachments/10082\Aushang 201501 Gr�ndung.pdf" }
The output should be done with the following code, but I think the problem is the reading of the files.
Html::a($model['name'], ['document/download', 'file' => $model['name']])
OK thanks #ineersa for trying to help, I got the answer with help from my coworker.
The solution is to explicit convert the filename returned by findFiles() to UTF-8 with the PHP function utf8_encode()
http://php.net/manual/en/function.utf8-encode.php
Related
I'm trying to use trans_choice() to simply format a string to either "comment" or "comments" depending on the number of them. It should be fairly straightforward, like this.
In my view:
{{ trans_choice('posts.num comments', $post->comments->count()) }}
In the posts localisation file:
return [
'num comments' => 'comment|comments',
];
However, every single one returns just "comment". And if I go into tinker:
>>> trans_choice('posts.num comments', 1);
=> "comment"
>>> trans_choice('posts.num comments', 2);
=> "comment"
>>> trans_choice('posts.num comments', 4);
=> "comment"
I'm sure I'm missing something obvious but it looks to me as if I've followed the documentation perfectly.
Edit: The problem seems to lie somewhere in Symfony\Component\Translation\MessageSelector, but I haven't yet figured the cause out.
Finally found the answer. Apparently, if the locale isn't available in Symfony's PluralizationRules class, the translator defaults to the first pick - that is, always index zero. By changing the locale name (I didn't even realise it was misspelled...), I got it working.
I know this post is old, but I ran into this issue, so hoping my solution helps someone if Joel's solution doesn't work.
I'm working with Laravel 7.x, and am using localization on a project for differences between US an CA English, (i.e. Center vs. Centre).
I have my localization folders set up with en being the default folder and en_ca as the Canadian English folder, where en is also the fallback language.
When using trans_choice() I found I had to specifically set the the counts in my translation strings, otherwise the translation engine would just spit back the singular when viewing pages in the non-default locale.
Once the changes were made, trans_choice() worked, no matter what locale was set.
For example, wherever I had:
'general.posts' => 'Posts|Posts',
I changed it to:
'general.posts' => '{1} Post|[2,*] Posts',
After that everything worked.
If you're brazilian that's probably your answer!
I just had the same problem and found out it was because of my locale option (and lang folder).
Instead of 'br' we must use 'xbr' in order to Symphony find it in PluralizationRules (vendor/symphony/translation/PluralizationRules).
In that file there's an array with all languages available, so may check it out.
P.S. I'm using Laravel 5.3
I'm very new to R and confused with two different results from RGui and RStudio (Both are ver.3.1.1.)
For some reasons, I have to put my R codes (txt format) in my Dropbox public folder and call it using the "source" code such as:
source("https://dl.dropboxusercontent.com/u/12900679/help.txt")
However, it doesn't work with RGui but does work with RStudio.
Here are the returned results:
In RGui,
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) : unsupported URL scheme
In RStudio,
[1] "Help me"
This is my first stackoverflow question and I hope my question makes sense to you.
Thanks in advance,
DJ
R doesn't support sourcing of https URLs out of the box on Windows. You may need to have RGui start R with the --internet2 flag. If that isn't easy for you, there are other workarounds; this answer probably has what you're looking for:
Sourcing R script over HTTPS
I am working in visual basic 6.0 and attempting to retreive the server of a Queue. So far the only way I have found to get this is from the path name (oQueue.QueueInfo.PathName) (which gives me: vdi***\testQueue02)
I would like to trim this down to just vdi***\
But I can not do it by number of characters because I have hundreds of queues all with different lenghts and also the servers may have different lenghts.
Is there any way to do this??
Thanks,
Is it always the "first part" of the path name you are trying to retrieve?
`Dim newArray() as String = Split(oQueue.QueueInfo.PathName,"\")
Dim path = newArray(0) & "\"`
right now, I have a date that is displayed like this:
19\06\2013
what I want is this :
19\6\2013
my current smarty code is :
{$variable|date_format:"%e\%m\%Y"}
I tried using %n for the month (I assumed that anything that works on php will work in smarty) but it did not give me any result.
How can I display the month without a leading zero in Smarty? is there any workaround solutions? I do not want to edit and format the date in my php file.
Today I have the same problem and this works for me…
Windows server
This solution seems to work only on windows based servers (localhost in my case).
{$variable|date_format:"%d\%#m\%Y"}
Just put hash # before letter 'm'.
I'm using Smarty v3
Linux server:
I moved my project to remote server (probably linux) and hash sign stop to work. I found another solution, just put hyphen - before letter 'm':
{$variable|date_format:"%d\%-m\%Y"}
And this works on linux, but not on windows.
Cross-platform PHP-based solution:
But because smarty is a PHP plugin we can use all of PHP functions. So this is another solution I found, maybe not so elegant but it seems to work everywhere.
{assign var="dateTime" value=$variable|strtotime}
{*
or shorter:
{$dateTime=$variable|strtotime}
*}
<p>{"j/n/Y"|date:$dateTime}</p>
Note:
The above solutions work for formatting day with out leading zero also:
{$variable|date_format:"%-d vs %d vs %#d"}
{$variable|date_format:"j. n. Y":"":"any string - not either strftime or auto"}
then you can write date format as in php function date().
smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto')
I use the ruby-gem sequel to read utf-8-encoded data from a MSSQL-Server table.
The fields of the table are defined as nvarchar, they look correct in the Microsoft Server Management Studio (Cyrillic is Cyrillic, Chinese looks chinese).
I connect my database with
db = Sequel.connect(
:adapter=>'ado',
:host =>connectiondata[:server],
:database=>connectiondata[:dsn],
#Login via SSO
)
sel = db[:TEXTE].filter(:language=> 'EN')
sel.each{|data|
data.each{|key, val|
puts "#{val.encoding}: #{val.inspect}" #-> CP850: ....
puts val.encode('utf-8')
}
}
This works fine for English, German returns also a useable result:
CP850: "(2 St\x81ck) f\x81r
(2 Stück) für ...
But the result is converted to CP850, it is not the original UTF-8.
Cyrillic languages (I tested with Bulgarian) and Chinese produce only '?'
(reasonable, because CP850 doesn't include Chinese and Bulgarian characters).
I also connected via a odbc-connection:
db = Sequel.odbc(odbckey,
:db_type => 'mssql', #necessary
#:encoding => 'utf-8', #Only MySQL-Adapter
)
The result is ASCII-8BIT, I have to convert the data with force_encoding to CP1252 (not CP850!).
But Cyrillic and Chinese is still not possible.
What I tried already:
The MySQL-adapter seems to have an encoding option, with MSSQL I detected no effect.
I did similar tests with sqlite and sequel and I had no problem with unicode.
I installed SQLNCLI10.dll and used it as provider. But I get a Invalid connection string attribute-error (same with sqlncli).
So my closing question: How can I read UTF-8 data in MS-SQL via ruby and sequel?
My environment:
Client:
Windows 7
Ruby 1.9.2
sequel-3.33.0
Database:
SQL Server 2005
Database has collation Latin1_General_CI_AS
After preparing my question I found a solution. I will post it as an answer.
But I still hope, there is a better way.
If you can avoid it, you really don't want to use the ado adapter (it's OK for read-only workloads, but I wouldn't recommend it for other workloads). I would try the tinytds adapter, as I believe that will handle encodings properly, and it defaults to UTF-8.
Sequel itself does not do any transcoding, it leaves the handling of encodings to the lower level driver.
After preparing my question I found a solution on my own.
When I add a
Encoding.default_external='utf-8'
to my code, I get the correct results.
As a side effect each File.open expects now also UTF-8-encoded files (This can be overwritten by additional parameters in File.open).
As an alternative, this works also:
Encoding.default_internal='utf-8'
As I mentioned in my question, I don't like to change global settings, only to change the behaviour of one interface.
So I still hope on a better solution.