Example #1
0
def macro_function_i18n(call_node, arg_map, compiler):
    # generate a fake translation for now to verify this is working
    # most apps will have to stub this part out somehow i think
    # in the context of a function, the goal is to replace a function with a
    # translated literal string. we have to do some shenanigans since Spitfire
    # doesn't parse repr(unicode)
    msg_arg_node = call_node.arg_list.parg_list[0]
    if not isinstance(msg_arg_node, ast.LiteralNode):
        raise analyzer.SemanticAnalyzerError(
            '$i18n argument "%s" must be a string literal' % msg_arg_node)
    i18n_msg = text.i18n_mangled_message(msg_arg_node.value)
    i18n_msg_utf8 = i18n_msg.encode(sys.getdefaultencoding())
    return u"'%s'" % i18n_msg.replace("'", "\\'")
Example #2
0
def make_i18n_message(raw_msg, macro_ast):
    # top should be a fragment and due to the limited syntax, we can more or
    # less scan this one level of nodes -- there are no nested i18n sections yet
    output = StringIO.StringIO()
    for i, n in enumerate(macro_ast.child_nodes):
        #print i, type(n), "start", n.start, "end", n.end
        #print "raw:", "'%s'" % raw_msg[n.start:n.end]

        if isinstance(n, ast.PlaceholderSubstitutionNode):
            raw_placeholder_expression = raw_msg[n.start:n.end]
            #output.write(make_placeholder_name(n))
            output.write(raw_placeholder_expression)
        else:
            output.write(text.i18n_mangled_message(n.value))
    return output.getvalue()