src: move pseudo-toplevel methods from Object
[nit.git] / src / frontend / i18n_phase.nit
index 6e373e6..fac760c 100644 (file)
@@ -130,8 +130,9 @@ end
 redef class AStringExpr
 
        redef fun accept_string_finder(v) do
 redef class AStringExpr
 
        redef fun accept_string_finder(v) do
-               var str = value.as(not null).escape_to_c
-               var parse = v.toolcontext.parse_expr("\"{str}\".get_translation(\"{v.domain}\", \"{v.languages_location}\").unescape_nit")
+               var str = value.as(not null).escape_to_gettext
+               var code = "\"{str}\".get_translation(\"{v.domain}\", \"{v.languages_location}\")"
+               var parse = v.toolcontext.parse_expr(code)
                replace_with(parse)
                v.add_string(str, location)
        end
                replace_with(parse)
                v.add_string(str, location)
        end
@@ -152,9 +153,10 @@ redef class ASuperstringExpr
                                fmt += exprs.length.to_s
                        end
                end
                                fmt += exprs.length.to_s
                        end
                end
-               fmt = fmt.escape_to_c
+               fmt = fmt.escape_to_gettext
                v.add_string(fmt, location)
                v.add_string(fmt, location)
-               var parse = v.toolcontext.parse_expr("\"{fmt}\".get_translation(\"{v.domain}\", \"{v.languages_location}\").unescape_nit.format()")
+               var code = "\"{fmt}\".get_translation(\"{v.domain}\", \"{v.languages_location}\").format()"
+               var parse = v.toolcontext.parse_expr(code)
                if not parse isa ACallExpr then
                        v.toolcontext.error(location, "Fatal error in i18n annotation, the parsed superstring could not be generated properly")
                        return
                if not parse isa ACallExpr then
                        v.toolcontext.error(location, "Fatal error in i18n annotation, the parsed superstring could not be generated properly")
                        return
@@ -217,3 +219,10 @@ class POFile
                f.close
        end
 end
                f.close
        end
 end
+
+redef class Text
+       private fun escape_to_gettext: String
+       do
+               return escape_to_c.replace("\{", "\\\{").replace("\}", "\\\}")
+       end
+end