我正在寻找一种理智的方式来获取一个非翻译内容的ugettext_lazy字符串.我找到了两种方法,但我对其中任何一种都不满意:
the_string = ugettext_lazy('the content')
the_content = the_string._proxy____args[0] # ewww!
Run Code Online (Sandbox Code Playgroud)
要么
from django.utils.translation import activate, get_language
from django.utils.encoding import force_unicode
the_string = ugettext_lazy('the content')
current_lang = get_language()
activate('en')
the_content = force_unicode(the_string)
activate(current_lang)
Run Code Online (Sandbox Code Playgroud)
第一段代码访问一个已明确标记为私有的属性,因此无法确定此代码的工作时间.第二种解决方案过于冗长和缓慢.
当然,在实际代码中,ugettext_lazyied字符串的定义和访问它的代码是appart.
问题是数组中包含的数据类型直到运行时才知道.我创建了一个测试用例来说明我的问题.一切正常,直到阵列.
User user1 = new User(1, "one");
User user2 = new User(2, "two");
User [] users = {user1, user2};
Gson gson = new Gson();
// gson processing array of known a type. WORKS FINE
// observe use of brackets []
String toJson = gson.toJson(users, User[].class);
User [] newUsers = gson.fromJson(toJson, User[].class);
for(User user : newUsers) {
System.out.println(user.toString());
}
// gson processing using reflection for single user. WORKS FINE
final Class<?> userType = Class.forName("com.abc.ws.GsonTest$User");
User user3 = new User(3, "three");
toJson …Run Code Online (Sandbox Code Playgroud) 编译此规范时:
import org.specs.Specification
import org.specs.matcher.extension.ParserMatchers
class ParserSpec extends Specification with ParserMatchers {
type Elem = Char
"Vaadin DSL parser" should {
"parse attributes in parentheses" in {
DslParser.attributes must(
succeedOn(stringReader("""(attr1="val1")""")).
withResult(Map[String, AttrVal]("attr1" -> AttrVal("val1", "String"))))
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ParserSpec.scala:21
error: scala is not an enclosing class
withResult(Map[String, AttrVal]("attr1" -> AttrVal("val1", "String"))))
^
Run Code Online (Sandbox Code Playgroud)
我根本不理解这里的错误信息.它为什么会出现?
Scala版本是2.8.1,规格版本是1.6.7.2.
DslParser.attributes有类型Parser[Map[String, AttrVal]]和组合器succeedOn,withResult定义如下:
trait ParserMatchers extends Parsers with Matchers {
case class SucceedOn[T](str: Input,
resultMatcherOpt: Option[Matcher[T]]) extends Matcher[Parser[T]] { …Run Code Online (Sandbox Code Playgroud) 我见过的大多数代码示例都显示了添加的图像.我正在寻找一个示例,基本上只显示大约10-15行数据被添加到UIScrollVIew.
任何可靠的建议都将受到高度赞赏.
请帮忙.
我想添加这些选项,其中goodMan并购买蝙蝠,斧头或剑来对抗怪物.
如何创建这3个数组,然后从中获取单个变量.然后使用这些变量来影响游戏的结果?
public static void main(String[] args)
throws IOException
{
int count = 1;
// start both with 1 point
int goodTotal = 50;
int monTotal = 50;
int moneyAmt = 10;
// input switch statement
loop: while (goodTotal > 0 && monTotal > 0) {
System.out.print("Type a letter: ");
System.out.println("\n");
System.out.print("F: Go out and Fight ");
System.out.println("\n"); …Run Code Online (Sandbox Code Playgroud) 好吧,我有几个UITextFields并且UITextViews在里面UIScrollView,我想设置键盘在scrollview触摸或滚动时消失(当然,当你在文本字段/视图内部触地时).
我目前尝试这样做是替换UIScrollView子类,并将其设置为在touchesBegan方法内调用removeKeyboard函数(在主视图控制器中定义).但是,这只会移除键盘以进行正常触摸,而不是仅在滚动视图时.那么,删除内部键盘的最佳方法是UIScrollView什么?
在此先感谢您的帮助.
我想创建一个方法,允许我更改从我的基类派生的类的任意属性,结果应如下所示:SetPropertyValue("size.height", 50);- where size是我的派生类height的属性,是一个属性size.
我差不多完成了我的实现,但是在继续之前我想要解决的最后一个障碍,为了描述这个,我首先要解释一下我的实现:
该SetPropertyValue方法的作用是:
size)一些示例代码进一步澄清:
private static Dictionary<RuntimeTypeHandle, object> EditableTypes; //property-modifier-dictionary
protected void SetPropertyValue<T>(EditablePropertyMap<T> map, string property, object value) {
var property = map[property]; // get the property modifier
property.Set((T)this, value); // use the set delegate (encapsulated in a method)
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,T是实际(派生)类的类型.我需要这种类型的get/set委托.问题是如何在EditablePropertyMap<T>不知道T是什么时获得.
我当前(丑陋)的解决方案是在派生类中的覆盖虚方法中传递映射:
public override void SetPropertyValue(string property, object value) {
base.SetPropertyValue((EditablePropertyMap<ExampleType>)EditableTypes[typeof(ExampleType)], property, …Run Code Online (Sandbox Code Playgroud) 是否有可能让rvm知道在某个目录下导航时应该使用哪个gemset,就像你可以通过在该目录下导航git当前分支的信息一样?
我理解git是如何工作的,因为每个目录在根目录中都有自己的.git目录,但不知道是否可能,因为.rvm更像是用户范围的配置.或者答案是在每个目录中创建一个.rvm文件?
我使用HTTP PUT方法编写了一个上传文件的服务.
Web浏览器不支持PUT,因此我需要一种测试方法.它可以很好地用作从浏览器访问它的POST.
更新:这是有效的.我尝试了海报,但它与使用提琴手一样.您必须知道如何构建请求.卷曲处理问题.
curl -X PUT"localhost:8080/urlstuffhere"-F"file = @ filename"-b"JSESSIONID = cookievalue"
在php中,该方法ucwords转换字符串中的任何字符串,其中每个单词的第一个字符是大写,而所有其他字符都是小写.
我总是最终制作自己的实现,我想知道是否存在标准方法.