当前位置: 首页>>代码示例>>Python>>正文


Python i18n.i18n函数代码示例

本文整理汇总了Python中pygobstoneslang.common.i18n.i18n函数的典型用法代码示例。如果您正苦于以下问题:Python i18n函数的具体用法?Python i18n怎么用?Python i18n使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了i18n函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load

  def load(self, board, f):
    contents = f.read()
    sizes = list(re.findall('\\GbstnTamanho{([0-9]+)}{([0-9]+)}', contents))
    if len(sizes) != 1:
      raise basic.BoardFormatException(i18n.i18n('Malformed tex board'))
    width, height = board.size = int(sizes[0][0]), int(sizes[0][1])
    board.head = (0, 0)
    board._clear_board()
    for coli in range(4):
      col = gbs_builtins.Color(coli).name()
      col_stones = re.findall('\\Gbstn' + col + '{([0-9]+)}{([0-9]+)}{([0-9]+)}' % (), contents)
      for x, y, count in col_stones:
        x, y, count = int(x), int(y), int(count)
        if x >= width or y >= height:
          raise basic.BoardFormatException(i18n.i18n('Malformed tex board'))
        board.cells[y][x].set_num_stones(coli, count)
    headers = list(re.findall('\\GbstnCabezal{([0-9]+)}{([0-9]+)}', contents))
    if len(headers) > 1:
      raise basic.BoardFormatException(i18n.i18n('Malformed tex board'))
    elif len(headers) == 1:
      x, y = int(headers[0][0]), int(headers[0][1])
      if x >= width or y >= height:
        raise basic.BoardFormatException(i18n.i18n('Malformed tex board'))

      board.head = y, x
    board.clear_changelog()
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:26,代码来源:fmt_tex.py

示例2: parse_atom

 def parse_atom(self, tree):
     if tree.children[0] == 'type':
         tok = tree.children[1]
         args = tree.children[2]
         if args is None:
             args = []
         else:
             args = [self.parse_atom(a) for a in args.children]
         if tok.value in BasicTypes:
             t = BasicTypes[tok.value]
             if t.kind_arity != len(args):
                 msg = i18n.i18n('type "%s" expects %u parameters, but receives %u') % (
                       tok.value, t.kind_arity, len(args))
                 area = position.ProgramAreaNear(tok)
                 raise GbsTypeSyntaxException(msg, area)
             return t(*args)
         else:
             if tok.value in self.context.keys():
                 return self.context[tok.value]
             else:
                 """[TODO] Translate """
                 msg = i18n.i18n('Undefined type "%s".') % (tok.value,)
                 area = position.ProgramAreaNear(tok)
                 raise GbsTypeSyntaxException(msg, area)
     elif tree.children[0] == 'typeVar':
         tok = tree.children[1]
         if tok.value in self.typevars:
             return self.typevars[tok.value]
         else:
             fresh = GbsTypeVar(tok.value)
             self.typevars[tok.value] = fresh
             return fresh
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:32,代码来源:gbs_type.py

示例3: check

 def check(self, options):
     if options['src']:
         self.check_file_exists(options['src'])
     if options['from']:
         self.check_file_exists(options['from'])
     if options['lint'] not in lang.GobstonesOptions.LINT_MODES:
         raise OptionsException(i18n.i18n('%s is not a valid lint option.') % (options['lint'],))
     if not self.check_size(options['size']):
         raise OptionsException(i18n.i18n('Size %s is not a valid size. Positive integers expected.') % (str(options['size']),))
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:9,代码来源:__main__.py

示例4: parse

 def parse(self, filename, program_text):
     # Parse gobstones script
     self.api.log(i18n.i18n('Parsing.'))
     tree = self._parse(program_text, filename)
     assert tree
     # Explode macros
     self.api.log(i18n.i18n('Exploding program macros.'))
     self.explode_macros(tree)
     return GobstonesRun().initialize(tree)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:9,代码来源:__init__.py

示例5: _warn_conflict

 def _warn_conflict(self, nonterminal, terminal, area):
     "Emits a warning for a conflictive state."
     msg = ''
     msg += i18n.i18n('Conflictive rule for: ("%s", "%s")\n') % (
                 nonterminal, terminal)
     msg += i18n.i18n('Will choose first production:\n')
     msg += utils.indent(bnf_rule_to_str(
                     self._parse_table[(nonterminal, terminal)]))
     self.warn(ParserException(msg, area))
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:9,代码来源:bnf_parser.py

示例6: _set_routine_definition_type

 def _set_routine_definition_type(self, tree, prfn, name, params, body):
     """Given a context with types for the parameters and local
     variables in a routine, build the type for this routine
     and unify it with its type in the global context.
     For instance if the function "f" has a parameter "x",
     and returns an expression, take the type "s" for "x"
     from the local context, the type "t" for the returned
     expression. Build the type "s -> t" for the function
     and unify that with any type information previously
     known for "f". This requires that the body of the routine
     has already been typechecked."""
     param_types = []
     for p in params.children:
         param_types.append(self.context[p.value])
     param_types = gbs_type.GbsTupleType(param_types)
     if prfn == 'procedure':
         def_type = gbs_type.GbsProcedureType(param_types)
     elif prfn == 'function':
         return_types = self._return_type(prfn, name, params, body)
         def_type = gbs_type.GbsFunctionType(param_types, return_types)
     elif prfn == 'entrypoint' and (name.value == 'program' or name.value == 'interactive'):
         def_type = gbs_type.GbsEntryPointType()
     else:
         assert False
     expected = self.global_context[name.value].instantiate()
     try:
         gbs_type.unify(expected, def_type)
         if prfn == 'function': #[TODO] Check
             freevars = def_type.freevars()
             if len(freevars) > 0:
                 def_type = gbs_type.GbsForallType(freevars, def_type)
                 self.global_context[name.value] = def_type
         tree.type_annot = def_type
     except gbs_type.UnificationFailedException as e:
         area = position.ProgramAreaNear(tree)
         if prfn == 'procedure':
             msg = i18n.i18n(
                       'procedure "%s" should take: %s\n' +
                       'But takes: %s'
                   ) % (
                       name.value,
                       expected.paramtype(),
                       def_type.paramtype()
                   )
         else:
             msg = i18n.i18n(
                       'function "%s" should take: %s and return: %s\n' +
                       'But takes: %s and returns: %s'
                   ) % (
                       name.value,
                       expected.paramtype(), expected.restype(),
                       def_type.paramtype(), def_type.restype()
                   )
         self.error(GbsTypeInferenceException(msg, area))
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:54,代码来源:gbs_infer.py

示例7: _error_conflictive_definition

 def _error_conflictive_definition(self, tree, name, as_type, val):
     if val.name() == name:
         area = position.ProgramAreaNear(tree)
         l1 = i18n.i18n('"%s" is not a ' + as_type) % (name,)
         l2 = i18n.i18n(val.type() + ' "%s" defined %s') % (name, val.where())
         raise GbsLintException('\n'.join([l1, l2]), area)
     else:
         area = position.ProgramAreaNear(tree)
         msg = i18n.i18n('"%s" is too similar to ' + val.type() + ' "%s", defined %s') % (
                         name, val.name(), val.where())
         raise GbsLintException(msg, area)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:11,代码来源:gbs_lint.py

示例8: fail

 def fail(msg):
     raise basic.BoardFormatException(
         i18n.i18n("Malformed gbb board")
         + "\n"
         + "  "
         + i18n.i18n("Near line:")
         + ' "'
         + orig[0].strip("\r\n")
         + '"\n'
         + "  "
         + msg
     )
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:12,代码来源:fmt_gbb.py

示例9: _put_from_description

 def _put_from_description(self, cell, description):
   coli = 0
   for cn in gbs_builtins.COLOR_NAMES:
     if description[-1].lower() == cn[0].lower():
       count = description[:-1]
       for l in count:
         if l not in '0123456789':
           raise basic.BoardFormatException(i18n.i18n('Malformed board'))
       cell.put(coli, int(count))
       return
     coli += 1
   raise basic.BoardFormatException(i18n.i18n('Malformed board'))
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:12,代码来源:fmt_gbt.py

示例10: _add_index

 def _add_index(self, varName, tree):
     var = self.symbol_table.check_not_defined_or_defined_as(tree, varName, 'atomic', ['index', 'variable', 'parameter'])
     if var is None:
         self.symbol_table.add(gbs_constructs.UserIndex(varName, tree))
     elif var.type() == 'variable':
         msg = i18n.i18n('Index of a foreach/repeatWith/repeat cannot be a variable: "%s"') % (varName,)
         area = position.ProgramAreaNear(tree)
         raise GbsLintException(msg, area)
     elif var.type() == 'parameter':
         msg = i18n.i18n('Index of a foreach/repeatWith/repeat cannot be a parameter: "%s"') % (varName,)
         area = position.ProgramAreaNear(tree)
         raise GbsLintException(msg, area)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:12,代码来源:gbs_lint.py

示例11: _add_var

 def _add_var(self, varName, tree):
     var = self.symbol_table.check_not_defined_or_defined_as(tree, varName, 'atomic', ['variable', 'index', 'parameter'])
     if var is None:
         self.symbol_table.add(gbs_constructs.UserVariable(varName, tree))
     elif var.type() == 'index':
         msg = i18n.i18n('Cannot modify "%s": index of a foreach/repeatWith/repeat is immutable') % (varName,)
         area = position.ProgramAreaNear(tree)
         raise GbsLintException(msg, area)
     elif var.type() == 'parameter':
         msg = i18n.i18n('Cannot modify "%s": parameter is immutable') % (varName,)
         area = position.ProgramAreaNear(tree)
         raise GbsLintException(msg, area)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:12,代码来源:gbs_lint.py

示例12: parse_error

 def parse_error(self, nonterminal, previous_token, token):
     "Raises a GbstonesParserException describing a parse error."
     area = position.ProgramAreaNear(token)
     if previous_token.type == 'lowerid' and token.type == '(':
         raise GbsParserException(i18n.i18n('Cannot call a function here'), area)
     elif previous_token.type == 'upperid' and token.type == '(':
         raise GbsParserException(i18n.i18n('Cannot call a procedure here'), area)
     elif previous_token.type == 'upperid' and token.type != '(':
         msg = i18n.i18n('Procedure name "%s" is missing a "("') % (previous_token.value,)
         raise GbsParserException(msg, area)
     elif token.type == 'EOF':
         raise GbsParserException(i18n.i18n('Premature end of input'), area)
     bnf_parser.Parser.parse_error(self, nonterminal, previous_token, token)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:13,代码来源:gbs_parser.py

示例13: build_special_key

 def build_special_key(self):
     return [
             self.build_key(i18n.i18n("K_ARROW_LEFT"), GobstonesKeys.ARROW_LEFT),
             self.build_key(i18n.i18n("K_ARROW_UP"), GobstonesKeys.ARROW_UP),
             self.build_key(i18n.i18n("K_ARROW_RIGHT"), GobstonesKeys.ARROW_RIGHT),
             self.build_key(i18n.i18n("K_ARROW_DOWN"), GobstonesKeys.ARROW_DOWN),
             self.build_key('K_ENTER', 13),
             self.build_key('K_SPACE', 32),
             self.build_key('K_DELETE', 46),
             self.build_key('K_BACKSPACE', 8),
             self.build_key('K_TAB', 9),
             self.build_key('K_ESCAPE', 27),
             ]
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:13,代码来源:gbs_io.py

示例14: check_unused_assignVarTuple1

 def check_unused_assignVarTuple1(self, tree):
   varnames = [v.value for v in tree.children[1].children]
   any_used = False
   for v in varnames:
     if v in tree.live_out:
       any_used = True
       break
   if not any_used:
     if len(varnames) == 1:
       msg = i18n.i18n('Variable "%s" defined but not used') % (varnames[0],)
     else:
       msg = i18n.i18n('Variables "(%s)" defined but not used') % (
                 ', '.join(varnames),)
     area = position.ProgramAreaNear(tree)
     raise GbsUnusedVarException(msg, area)
开发者ID:gobstones,项目名称:pygobstones-lang,代码行数:15,代码来源:gbs_liveness.py

示例15: check_return_arity

 def check_return_arity(self, def_comp, tree, ret_arity):
     prfn = def_comp.type()
     name = def_comp.name()
     nretvals = def_comp.num_retvals()
     if nretvals != ret_arity:
         area = position.ProgramAreaNear(tree)
         if nretvals == 1:
                             l1 = i18n.i18n('Function "%s" returns one value') % (name,)
         else:
                             l1 = i18n.i18n('Function "%s" returns %i values') % (name, nretvals)
         if ret_arity == 1:
             l2 = i18n.i18n('One value is expected')
         else:
             l2 = i18n.i18n('%i values are expected') % (ret_arity,)
         raise GbsLintException('\n'.join([l1, l2]), area)
开发者ID:ncastrohub,项目名称:labo_tp_2s_2015,代码行数:15,代码来源:gbs_lint.py


注:本文中的pygobstoneslang.common.i18n.i18n函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。