我试图生成一个本地化的日期字符串strftime,我使用的占位符是%x.语言/语言环境是setlocale(LC_ALL, array('jp','japanese')),但两个语言环境都不可用,因此它生成了一个包含不正确字符的字符串.然后我安装了ja_JP.utf8语言环境并指定它作为数组中的第一个元素,并解决了我的日期格式问题.
我的问题是,我应该总是依赖于安装的语言环境吗?我知道如何在我有root权限的盒子上安装它们,但是如果我没有访问权限呢?
我相信Zend_Locale并且Zend_Translate根本不依赖,setlocale但不知何故在内部进行,这给我的印象是它对于企业级应用程序实际上是不可行的.
我知道我大概可以用Zend_Locale和Zend_Translate我的应用程序,但它也需要支持PHP4,至少再延长一年这就是为什么我不能完全依赖这些.
我在我的电脑上使用俄语语言环境设置.
如果我愿意:
class numpunct_withpoint: public numpunct<char>
{
protected:
/// Override the function that gives the decimal separator.
char do_decimal_point() const
{
return '.';
}
};
...
locale loc(std::locale::classic(), new numpunct_withpoint);
std::locale::global(loc);
Run Code Online (Sandbox Code Playgroud)
然后
printf("%f", 3.14);
Run Code Online (Sandbox Code Playgroud)
输出是:
3,14
Run Code Online (Sandbox Code Playgroud)
小数分隔符是","不像do_decimal_point函数!如何使用C++语言环境更改小数分隔符的C语言环境设置?
谢谢你的回答!
但是,C setlocale函数会对C++ cout对象产生影响吗?
setlocale(LC_NUMERIC, "C");
Run Code Online (Sandbox Code Playgroud)
这会在通过cout打印十进制值时产生影响吗?
int main(int argc, char *argv[])
{
char *ret = setlocale(LC_ALL, NULL);
// should I free 'ret' ???
// free(ret);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我已经在Linux和OS X 10.10上尝试过,在Linux上,我不能称之为'免费',但在OS X上,如果我不调用'free',valgrind会抱怨内存泄漏.
==62032== Memcheck, a memory error detector
==62032== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==62032== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==62032== Command: ./a.out
==62032==
--62032-- ./a.out:
--62032-- dSYM directory is missing; consider using --dsymutil=yes
==62032==
==62032== HEAP SUMMARY:
==62032== in use at exit: 129,789 bytes …Run Code Online (Sandbox Code Playgroud) 很简单:我正在使用Smarty和|capitalize修饰符.它工作正常,但当我传入任何单词时l,它会将其大写,即使它不在单词的开头.
什么为什么?
编辑:同样的事情p.
测试:
{"abcdefghijklmnopqrstuvwxyz"|capitalize}
{"aaal aala alaa laaa"|capitalize}
{"aaap aapa apaa paaa"|capitalize}
Run Code Online (Sandbox Code Playgroud)
输出:
AbcdefghijkLmnoPqrstuvwxyz
AaaL AaLa ALaa Laaa
AaaP AaPa APaa Paaa
Run Code Online (Sandbox Code Playgroud) 我有这个代码,通过json_decode检索我的最新推文,他们的日期等.
<?php setlocale(LC_ALL, 'it_IT'); ?>
<?php include("twitter_auth.php");
echo "<ul style='color:#6E6E6E'>";
foreach ($twitter_data as $tweet)
{
if (!empty($tweet)) {
$text = $tweet->text;
$text_in_tooltip = str_replace('"', '', $text); // replace " to avoid conflicts with title="" opening tags
$id = $tweet->id;
$time = strftime('%d %B', strtotime($tweet->created_at));
$username = $tweet->user->name;
}
echo '<li><span title="'; echo $text_in_tooltip; echo '">'; echo $text . "</span><br>
<a href=\"http://twitter.com/"; echo $username ; echo '/status/'; echo $id ; echo '"><small>'; echo $time; echo '</small></a> -
<a href="http://twitter.com/intent/tweet?in_reply_to='; echo $id; …Run Code Online (Sandbox Code Playgroud) 我尝试用德语显示日期,但它不起作用.我正在使用PHP和XAMPP.
这些是我的方法:
function get_Datetime_Now() {
setlocale (LC_TIME, "de_DE");
$tz_object = new DateTimeZone('Europe/Zurich');
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
return $datetime->format('l, d. F Y ');
}
echo get_Datetime_Now();
Run Code Online (Sandbox Code Playgroud)
它返回"2014年2月9日星期日",但我不是"Sonntag,09.2014年2月"(德语).
我也试过这个:
setlocale(LC_TIME, "de_DE");
echo strftime("%A, %d. %B %Y");
Run Code Online (Sandbox Code Playgroud)
它还返回"2014年2月9日星期日".我在互联网上看到了许多不起作用的例子(至少在我的环境中).
我应该检查设置吗?
我感谢任何帮助!
先谢谢,shivan
GCC 4.8,5.1,6.2和3.8.1锵在Ubuntu 16.10使用-std=c11,-std=c++11,-std=c++14,和-std=c++17都表现出使用时,这种怪异的行为fgetws(buf, (int) bufsize, stdin)后setlocale(LC_ALL, "any_THING.utf8");.
示例程序:
#include <locale.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
int main(const int argc, const char* const * const argv) {
(void) argc;
setlocale(LC_ALL, argv[1]);
const size_t len = 3;
wchar_t *buf = (wchar_t *) malloc(sizeof (wchar_t) * len),
*stat = fgetws(buf, (int) len, stdin);
wprintf(L"[%ls], [%ls]\n", stat, buf);
free(buf);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
Casting malloc仅适用于C++ - compat.
像这样编译:cc -std=c11 fg.c …
在我的应用程序中,我正在动态更改语言,因此如果我在前台,通知语言将正确出现,但如果我强制关闭应用程序通知将出现在设备区域设置中。
我使用以下代码来更改上下文语言环境,但在强制关闭后它不起作用
fun wrapContext(context: Context?, locale: Locale): Context? {
if (context == null) return null
val configuration = context.resources.configuration
if (getSystemLocale(configuration) === locale) {
return context
}
setSystemLocale(configuration, locale)
val res = context.resources
res.updateConfiguration(configuration, res.displayMetrics)
return context.createConfigurationContext(configuration)
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
notifications android push-notification setlocale android-notification-bar
这似乎是一个奇怪的问题,它引起了我的一些胃灼热,因为我正在使用一个存储当前语言环境的库,并尝试将其设置回它所存储的内容。
$ docker run --rm -it python:3.6 bash
root@bcee8785c2e1:/# locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=
Run Code Online (Sandbox Code Playgroud)
root@bcee8785c2e1:/# locale -a
C
C.UTF-8
POSIX
Run Code Online (Sandbox Code Playgroud)
root@bcee8785c2e1:/# python
Python 3.6.9 (default, Jul 13 2019, 14:51:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> curr = locale.getlocale()
>>> curr
('en_US', 'UTF-8')
>>> locale.setlocale(locale.LC_ALL, curr)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/locale.py", …Run Code Online (Sandbox Code Playgroud) 我的代码中有一个宽字符串(std :: wstring),我需要在其中搜索宽字符.
我使用find()函数:
wcin >> str;
wcout << ((str.find(L'?') != wstring::npos)? L"EXIST":L"NONE");
Run Code Online (Sandbox Code Playgroud)
L'?' 是一封西里尔字母.
但是同一个调用中的find()总会返回npos.在拉丁字母的情况下,find()可以正常工作.
这是这个功能的问题吗?或者我做错了什么?
UPD
我使用MinGW并以UTF-8保存源代码.我也设置了语言环境setlocale(LC_ALL, "");.代码相同的wcout << L'?';工作是coorectly.但同样的
wchar_t w;
wcin >> w;
wcout << w;
Run Code Online (Sandbox Code Playgroud)
工作不正确.
它很奇怪.之前我使用setlocale()编码没有问题.