[vala] Support translated string constants
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Support translated string constants
- Date: Tue, 8 Feb 2011 19:33:26 +0000 (UTC)
commit 7c2fd8a2a9d9503496c96854be95fa7f91ef44a6
Author: Jürg Billeter <j bitron ch>
Date: Tue Feb 8 20:32:35 2011 +0100
Support translated string constants
Fixes bug 641543.
codegen/valaccodebasemodule.vala | 13 ++++++++++++-
vala/valaconstant.vala | 15 +++++++++++++++
vala/valastringliteral.vala | 4 +++-
3 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 14258bc..328de67 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1,6 +1,6 @@
/* valaccodebasemodule.vala
*
- * Copyright (C) 2006-2010 Jürg Billeter
+ * Copyright (C) 2006-2011 Jürg Billeter
* Copyright (C) 2006-2008 Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
@@ -3424,6 +3424,17 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public override void visit_string_literal (StringLiteral expr) {
set_cvalue (expr, new CCodeConstant.string (expr.value.replace ("\n", "\\n")));
+
+ if (expr.translate) {
+ // translated string constant
+
+ var m = (Method) root_symbol.scope.lookup ("GLib").scope.lookup ("_");
+ add_symbol_declaration (cfile, m, m.get_cname ());
+
+ var translate = new CCodeFunctionCall (new CCodeIdentifier ("_"));
+ translate.add_argument (get_cvalue (expr));
+ set_cvalue (expr, translate);
+ }
}
public override void visit_regex_literal (RegexLiteral expr) {
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index fab450c..c9b880c 100644
--- a/vala/valaconstant.vala
+++ b/vala/valaconstant.vala
@@ -203,6 +203,21 @@ public class Vala.Constant : Symbol, Lockable {
return false;
}
+ // support translated string constants for efficiency / convenience
+ // even though the expression is not a compile-time constant
+ var call = value as MethodCall;
+ if (call != null) {
+ var method_type = call.call.value_type as MethodType;
+ if (method_type != null && method_type.method_symbol.get_full_name () == "GLib._") {
+ // first argument is string
+ var literal = call.get_argument_list ().get (0) as StringLiteral;
+ if (literal != null) {
+ value = literal;
+ literal.translate = true;
+ }
+ }
+ }
+
if (!value.is_constant ()) {
error = true;
Report.error (value.source_reference, "Value must be constant");
diff --git a/vala/valastringliteral.vala b/vala/valastringliteral.vala
index 69fc4d7..ffb4285 100644
--- a/vala/valastringliteral.vala
+++ b/vala/valastringliteral.vala
@@ -1,6 +1,6 @@
/* valastringliteral.vala
*
- * Copyright (C) 2006-2010 Jürg Billeter
+ * Copyright (C) 2006-2011 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,8 @@ public class Vala.StringLiteral : Literal {
*/
public string value { get; set; }
+ public bool translate { get; set; }
+
/**
* Creates a new string literal.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]