wagtail StreamField block name translation issue - translation

What I found in docs is the following:
The parameter to StreamField is a list of (name, block_type) tuples. ‘name’ is used to identify the block type within templates and the internal JSON representation (and should follow standard Python conventions for variable names: lower-case and underscores, no spaces) and ‘block_type’ should be a block definition object as described below. (Alternatively, StreamField can be passed a single StreamBlock instance - see Structural block types.)
'name' will be displayed in wagtail admin interface as the name of block.
Now I want to translate the name of blocks in StreamField.
I tried to use gettext and ugettext_lazy to wrap the name.
If gettext is used, then the display text on admin interface will be language of "LANGUAGE_CODE" in 'settings/base.py'. User specified language preference in admin interface will not make a difference.
If ugettext_lazy is used and user specified language differs from LANGUAGE_CODE in 'settings/base.py', there will be keyerrors where key is the translated content.
Is there a way to translate the name properly?

All block types accept a label argument for the name to display in the admin; you should apply the translation function there.
from django.utils.translation import ugettext_lazy as _
class MyPage(Page):
body = StreamField([
('heading', blocks.CharBlock(label=_("Heading"))),
])

Related

Type name as identifier in F#

I just started to study F# and accidentally wrote this binding
let List = 1
Now when I try to obtain List methods such as 'filter' I get this error
error FS0039: The field, constructor or member 'filter' is not defined.
Of course using method with full type name like Microsoft.FSharp.Collections.List.filter is still working.
I'm wondering why it is possible to use type name as identifier in F# and how I can set back name List to type List from Microsoft.FSharp.Collections.
When I tried to reassign like this
type List = Microsoft.FSharp.Collections.List<'T>
I get
Error FS0039: The type parameter 'T is not defined.
Thank you!
In F# you can redefine almost everything and shadow existing definitions. This applies to both types (well actually types have a different behavior regarding shadowing, they shadow their values as you open the namespaces) and values but not interchangeably since values and type (and also modules) can somehow coexist at the same time in the scope. The compiler will do his best to find out which one is.
You are not forced to, but it's a common good practice in F# not to use let bindings in uppercase.
Regarding your second question, you are using a type parameter in the right side which doesn't exist in the left side of the assignment, it should be:
type List<'T> = Microsoft.FSharp.Collections.List<'T>
But notice that filter doesn't belong to the type. It's rather defined in the List module.
You should just rename your let binding from List to something sensible - as Gustavo mentioned, your definition is shadowing the core List module from F# and there is no way to use List to refer both to your integer and to the module. Shadowing core functions will make your code pretty confusing. It's also a good idea to use camelCase for let bindings, but that's a matter of taste.
If you insist on shadowing List, then you won't be able to call List.filter using List.filter. If you wanted something shorter, you could define module alias:
module FsList = Microsoft.FSharp.Collections.List
Note that your attempt to do something similar with List<'T> does not do the same thing, because functions such as filter are in a module named List rather than being static members of the type. With this, you can call filter using FsList.filter.

Roles of Delphi function name in Obj files

what is the roles of function name that's Delphi does when compiling pas file.
for example the following code
unit Hellopas;
interface
function HelloFromPas():Integer; stdcall;
will preduce this function name #Hellopas#HelloFromPas$qqsv
so what is the Delphi roles for that?
This is a decorated or mangled name. The name encodes the full scope for the function, and its parameters. The unit name is included because that is part of the fully qualified name. The parameters, return value and calling convention are encoded also, here as qqsv.
Wikipedia explains the need for mangling like this:
In compiler construction, name mangling (also called name decoration)
is a technique used to solve various problems caused by the need to
resolve unique names for programming entities in many modern
programming languages.
It provides a way of encoding additional information in the name of a
function, structure, class or another datatype in order to pass more
semantic information from the compilers to linkers.
The need arises where the language allows different entities to be
named with the same identifier as long as they occupy a different
namespace (where a namespace is typically defined by a module, class,
or explicit namespace directive) or have different signatures (such as
function overloading).
Any object code produced by compilers is usually linked with other
pieces of object code (produced by the same or another compiler) by a
type of program called a linker. The linker needs a great deal of
information on each program entity. For example, to correctly link a
function it needs its name, the number of arguments and their types,
and so on.

Can you have a custom attribute in yang schema?

I wanted to know if we could define a custom field or attribute in one of the elements leaf,list etc. For eg: Is this possible? How can we define such fields if its possible.
model Animal{
leaf amphibian{
type String;
custom "Frog"; // Custom field which has a value "Frog"
}
}
An "attribute" as in a "new YANG keyword"
If by "attribute" you are referring to a new YANG keyword, that has special meaning to you, then yes. YANG supports extensions. From RFC6020:
The "extension" statement allows the definition of new statements
within the YANG language. This new statement definition can be
imported and used by other modules.
The statement's argument is an identifier that is the new keyword for
the extension and must be followed by a block of substatements that
holds detailed extension information. The purpose of the "extension"
statement is to define a keyword, so that it can be imported and used
by other modules.
The extension can be used like a normal YANG statement, with the
statement name followed by an argument if one is defined by the
extension, and an optional block of substatements. The statement's
name is created by combining the prefix of the module in which the
extension was defined, a colon (":"), and the extension's keyword,
with no interleaving whitespace.
extension custom {
argument object;
description "A new YANG keyword that carries special semantics.";
}
prefix:custom "Frog"; // usage of an extension
The argument keyword in the above example is an optional substatement to an extension keyword and is used to indicate that the new keyword takes (mandates) an argument (a string, such as "Frog").
The "argument" statement, which is optional, takes as an argument a
string that is the name of the argument to the keyword. If no
argument statement is present, the keyword expects no argument when
it is used.
7.17.2
Why do you need a named argument for the new keyword? YANG may be mapped to YIN, the alternative syntax expressed as XML and that is where this name becomes important.
The argument's name is used in the YIN mapping, where it is used as
an XML attribute or element name, depending on the argument's "yin-
element" statement.
7.17.2
You cannot restrict the value space of this argument per se - a YANG compiler will always recognize it as a string. But there is nothing stopping you from requiring implementations to expect certain values - you are defining the meaning of the new keyword after all.
extension custom {
argument value;
description
"The value of "custom" statement's argument MUST be an integer
in the range from 1 to 5.";
}
prefix:custom 3;
Description statements contain normative text, so if your extension contains a description substatement, stating that "value of this statement's argument MUST be an integer", then an implementation will have to respect this text.
An "attribute" as in an "XML attribute" (or a JSON equivalent)
If you meant an "attribute" in instance documents (XML, JSON,...) modeled with YANG, then the answer is no - for the most part. Pure YANG does not support modeling attributes.
However, there is a published specification for a YANG extension that allows such attributes to be defined. You can read more about that here (RFC7952). The extension is called annotation and is used to define YANG metadata, additional information that augments data that may already be modeled with YANG. Here's an example:
module using-annotation {
namespace "org:example:using-annotation";
prefix "ua";
import ietf-yang-metadata {
prefix "md";
}
md:annotation my-annotation {
type string;
description "This is my annotation.";
}
container top {
leaf some-leaf {
type string;
}
}
}
This would be a valid XML instance according to the above model:
<ua:top xmlns:ua="org:example:using-annotation">
<ua:some-leaf ua:my-annotation="Yay!">foo</ua:some-leaf>
</ua:top>
It allows an XML attribute to become valid almost anywhere.
Reading RFC7952 may also be useful for learning how the extension statement actually works and how to properly define a YANG extension.

How autocomplete in delphi?

I am using Delphi 7, when I write code in the unit, I want autocomplete the words of the tree's objects.
For example, I have the next objets: LabelName, LabelEdge, LabelWindow, I want start write LabelN and have the possibility of autocomplete to LabelName.
Is it possible?
As David Heffernan said in the comments you need to press the CTRL+Space key in order for code insight to provide you with available choices for auto-completion.
The available choices then depend on the part of the component name, method name, variable name, or constant name you have already written.
They also depend on your current code scope which means that code insight won't provide you choice to use some method, variable or constant if it can't be accessed from the method you are writing code in (local variables/constants that belong to other methods, private members of a different class, etc.)
You can invoke code insight to provide you choices even when you haven't written any partial name. In this case code insight will show you all available methods, variables, constants and objects (both components and classes) that can be accessed from within the current code scope. This is most useful when you are searching for specific method but you can't remember its name.

XOM Parser Element.getAttributeValue() returns null if attribute name has :

I have been using XOM parser in a project that is mostly over. The parser is very good and I find it mostly stable. However today I was parsing an XML element with an attribute called "xml:lang"
The getAttributeValue("xml:lang") returned null instead of "English". I could find a work around to get the value by using getAttribute(int location).getValue()
However, it would be better to use the method getAttributeValue because the attribute's location changes for other elements.
I am not sure whether I am doing something wrong or a small bug lies there in the library method.
The xml:lang attribute is in a namespace.
To get the value of an attribute in a namespace, use the Element.getAttributeValue(String, String) method. The first parameter needs to be the local name of the attribute (after the colon), which is lang in this case. The second parameter needs to be the URI of the namespace, which is usually defined in an ancestor element. The xml namespace, however, is built in and always has the namespace URI http://www.w3.org/XML/1998/namespace.
Therefore, some code like this should do what you want (assuming you have a variable called element pointing to your element):
String lang = element.getAttributeValue("lang", "http://www.w3.org/XML/1998/namespace");

Resources