EzDevInfo.com

translate

A Ruby on Rails plugin with a web interface for translating I18n texts

How to resize a button depending on its text

In the process of translating an application with C# + Winforms, I need to change a button's text depending on the language.

My problem is the following :

Let's say I want to translate a button from "Hi all!" to "Bonjour tout le monde" !

As you can guess, the button's size won't be the same if I enter english text or french one... My question is "simple", how can I manage to resize the button on the fly so the text fits its content in the button ?

So far I got something like that !

[Hi all!]

[Bonjour]

Thanks in advance for your help !

Andy


Source: (StackOverflow)

What is Python's equivalent of Java's standard for-loop?

I'm writing a simple algorithm to check the primality of an integer and I'm having a problem translating this Java code into Python:

for (int i = 3; i < Math.sqrt(n); i += 2) {
    if (n % i == 0)
        return false;
}

So, I've been trying to use this, but I'm obviously skipping the division by 3:

i = 3
while (i < int(math.sqrt(n))):
    i += 2  # where do I put this?
    if (n % i == 0):
        return False

Source: (StackOverflow)

Advertisements

Translate X and Y percentage values based on elements height and width?

Translating an elements Y axis 50% will move it down 50% of its own height, not 50% of the parents height as I would expect. How do I tell a translating element to base it's translation percentage on the parent element? Or am I not understanding something?

http://jsfiddle.net/4wqEm/2/


Source: (StackOverflow)

Translation in JavaScript like gettext in PHP?

I am using gettext in my PHP code, but I have a big problem. All my JavaScript files are not affected by the translation, can somebody tell me an easy way to get the translations in the chosen language into JavaScript as well.


Source: (StackOverflow)

How can I add momentum / inertia to a drag using CSS transform?

I am trying to add a momentum / inertia effect to a zoomed image drag (like in this example or just like iOs does it) and I'm having a tough time with it.

I've been struggling with this for a while and found some helpful resources (like this one) but most of the solutions involve jQuery and I would prefer to stick to plain javascript, no frameworks involved.

I'm working on a HTML5 / CSS3 zoom image code, with all the standard features: double-tap zoom, pinch zooming, dragging, panning, etc. and everything is done using CSS3's transform translation, combined with the scaling. Ex.

transform: translate(100px, 100px);
transition: 100ms;

I looked at how others are doing it and it involves consecutive animations of the left/right properties, with decreasing duration / distance, to create a sort of ease-in effect.

I tried to recreate it using translations, using a sort of recursive function (you can see a fiddle here (works with webkit browsers), please ignore the coding style, it was not meant to be best practice, just a demo). In this case, the animation is not fluid it all, the consecutive translations do not connect.

I have a somewhat basic understanding of the principle and I did take a look at some algorithms available online but I just can't figure out how can I achieve this using css translations.

The first part of the dragging, done on mousemove/touchmove moves the image with the cursor/finger but the continuing translation after the end is not... continuous, it's like a separate animation after the first one and doesn't resemble a natural momentum / inertia effect.


Source: (StackOverflow)

Getting an Objective-C class name without having a MonoTouch managed class

I can't for the life of me figure out how to translate this into MonoTouch. Any takers?

for(UIView* view in cell.subviews)
{
    if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
    {
    }
}

Mostly it's the View Class Description that has me stumped...


Source: (StackOverflow)

Scaled live iPhone Camera view in center, "CGAffineTransformTranslate" not working

I have a little problem which I could not solve. I really hope someone can help me with that. I wanted to resize the live camera view and place it in the center, using the following code below:

    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 0.5, 0.56206);
    picker.cameraViewTransform = CGAffineTransformTranslate(picker.cameraViewTransform, 80, 120);

But all I got was a scaled 1/2 sized view on the top left of the screen. It seems as though "CGAffineTransformTranslate" does nothing at all. The translation didn't work even when I used:

     picker.cameraViewTransform = CGAffineTransformMake(1, 0, 0, 1, 80, 120);

The translation portion seems to have no effect on the live camera view. Hope someone can enlighten me.

Thanks.


Source: (StackOverflow)

How to translate form labels in Zend Framework 2?

I'm not getting it!.. Can please someone explain, how to translate form labels? A simple example would be great.

Thank you in advance!


class Search\Form\CourseSearchForm

...

class CourseSearchForm extends Form {

    ...

    public function __construct(array $cities) {
        parent::__construct('courseSearch');
        ...
        $this->add(array(
            'name' => 'city',
            'type'  => 'Zend\Form\Element\Select',
            'options' => array(
                'label' => 'Stadt',
                'value_options' => $this->cities,
                'id'  => 'searchFormCity',
            ),
        ));
        ...
    }
}

view script /module/Search/view/search/search/search-form.phtml

<?php echo $this->form()->openTag($form); ?>
<dl>
    ...
    <dt><label><?php echo $form->get('city')->getLabel(); ?></label></dt>
    <dd><?php echo $this->formRow($form->get('city'), null, false, false); ?></dd>
    ...
</dl>
<?php echo $this->form()->closeTag(); ?>
<!-- The formRow(...) is my MyNamespace\Form\View\Helper (extends Zend\Form\View\Helper\FormRow); the fourth argument of it disables the label. -->

The module/Application/config/module.config.php is configured:

return array(
    'router' => ...
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'de_DE',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => ...
    'view_manager' => ...
);

I also edited my view and use the FormLabel view helper:

<dt><label><?php echo $this->formLabel($form->get('city')); ?></label></dt>

Furthermore I debugged the FormLabel at the place, where the tranlator is used (lines 116-120) -- seems to be OK.

But it's still not working.


EDIT

The (test) items for labels, I added to the de_DE.po file manually, are tranlated. The ZF2 side problem was actually, that I was using $form->get('city')->getLabel() instead of $this->formlabel($form->get('city')) in th view script.

The problem is now, that the labels are not added to the de_DE.po file. But it's not a ZF2 issue anymore, so I've accept Ruben's answer and open a new Poedit question.


Source: (StackOverflow)

Two conditions using OR in XPATH

I have a textbox, 'txtSearch'. I am using it to search people by Last Name. this is my code.

var xmlTempResultSearch = xmlResidentListDisplay.selectNodes(
    "//PeopleList/Row[contains(translate(@LastName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '" +
    txtSearch.value + "')]");

This code selects all last names in the XML like the text input in the txtSearch textbox.

This translates all uppercase letters to lowercase letters.

So if I am searching for 'Dorosan', if I type 'doro', it retrieves the correct person because it translated the 'D' to 'd'. But when I type 'Doro', it doesn't retrieve the correct person.

I'm wondering if I can have two conditions in an XPATH, and how? I want to be able to translate all uppercase to lowercase, OR translate all lowercase to uppercase.


Source: (StackOverflow)

Unescaping XML entities using XmlReader in .NET?

I'm trying to unescape XML entities in a string in .NET (C#), but I don't seem to get it to work correctly.

For example, if I have the string AT&amp;T, it should be translated to AT&T.

One way is to use HttpUtility.HtmlDecode(), but that's for HTML.

So I have two questions about this:

  1. Is it safe to use HttpUtility.HtmlDecode() for decoding XML entities?

  2. How do I use XmlReader (or something similar) to do this? I have tried the following, but that always returns an empty string:

    static string ReplaceEscapes(string text)
    {
        StringReader reader = new StringReader(text);
    
        XmlReaderSettings settings = new XmlReaderSettings();
    
        settings.ConformanceLevel = ConformanceLevel.Fragment;
    
        using (XmlReader xmlReader = XmlReader.Create(reader, settings))
        {
            return xmlReader.ReadString();
        }
    }
    

Source: (StackOverflow)

Building a parser (Part I)

I'm making my own javascript-based programming language (yeah, it is crazy, but it's for learn only... maybe?). Well, I'm reading about parsers and the first pass is to convert the code source to tokens, like:

if(x > 5)
  return true;

Tokenizer to:

T_IF          "if"
T_LPAREN      "("
T_IDENTIFIER  "x"
T_GT          ">"
T_NUMBER      "5"
T_RPAREN      ")"
T_IDENTIFIER  "return"
T_TRUE        "true"
T_TERMINATOR  ";"

I don't know if my logic is correct for that for while. On my parser it is even better (or not?) and translate to it (yeah, multidimensional array):

T_IF             "if"
  T_EXPRESSION     ...
    T_IDENTIFIER     "x"
    T_GT             ">"
    T_NUMBER         "5"
  T_CLOSURE        ...
    T_IDENTIFIER     "return"
    T_TRUE           "true"

I have some doubts:

  1. Is my way better or worse that the original way? Note that my code will be read and compiled (translated to another language, like PHP), instead of interpreted all the time.
  2. After I tokenizer, what I need do exactly? I'm really lost on this pass!
  3. There are some good tutorial to learn how I can do it?

Well, is that. Bye!


Source: (StackOverflow)

Can PyPy/RPython be used to produce a small standalone executable?

(Or, "Can PyPy/RPython be used to compile/translate Python to C/C++ without requiring the Python runtime?")

I have tried to comprehend PyPy with its RPython and its Python, its running and its compiling and its translating, and have somewhat failed.

I have a hypothetical Python project (for Windows); I would like to keep its size down, in the order of a hundred kilobytes (O.N.O.) rather than the several megabytes that using py2exe entails (after UPX). Can I use PyPy1 in any way to produce a standalone executable which does not depend on Python26.dll? If I can, does it need to follow the RPython restrictions like for only working on builtin types, or is it full Python syntax?

I do realise that if this can be done I almost certainly couldn't use C modules from Python directly.


1 (Since the time of asking, the situation has become clearer, and this part of the toolchain is more clearly branded as RPython rather than PyPy; it wasn't so in 2010.)


Source: (StackOverflow)

How to translate this enum from objective-c to swift?

I don't understand why & and << don't work in Swift. Please help me to translate objective-c code examples to Swift.

Example 1

UIViewController *viewController = [[UIViewController alloc] init];
viewController.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeTop;
if (viewController.edgesForExtendedLayout & UIRectEdgeBottom) {
    NSLog(@"got it!");
}

I'am trying to translate it in Swift but got an error

let viewController = UIViewController()
viewController.edgesForExtendedLayout = .Bottom | .Top
if viewController.edgesForExtendedLayout & .Bottom {
    println("got it!")
}

Example 2

typedef NS_OPTIONS(NSInteger, kViewControllerAnchoredGesture) {
    kViewControllerAnchoredGestureNone     = 0,
    kViewControllerAnchoredGesturePanning  = 1 << 0,
    kViewControllerAnchoredGestureTapping  = 1 << 1,
    kViewControllerAnchoredGestureCustom   = 1 << 2,
    kViewControllerAnchoredGestureDisabled = 1 << 3
};

Here I can't understand why << doesn't compile, how can I fix it?

enum kViewControllerAnchoredGesture: NSInteger {
    case None     = 0
    case Panning  = 1 << 0
    case Tapping  = 1 << 1
    case Custom   = 1 << 2
    case Disabled = 1 << 3
}

Thanks in advance!


Source: (StackOverflow)

Google-api-ruby-client Translate API Examples

I was very happy to see the google code: google-api-ruby-client project, because it meant to me that Ruby people can polish code with the Google API-s.

For now though I'm stumped because the only example given uses Buzz and from my experiments, the Google Translate (v2) api must behave quite differently to Buzz in the google-api-ruby-client.

I was intrigued by the 'Explorer' demo example -- But it isn't much of an explorer as far as I can see. All it does is call up a Buzz service and then pokes about in things it ALREADY knows about Buzz the services. To me, an explorer ought to let you 'discover' the services and the methods/functions exposed without necessarily knowing them already.

I'd love to hear of Ruby command line and desktop applications using this: google-api-ruby-client for services other than Buzz and in particular the Translate api (I'm less interested in the existing Ruby gems using the translate service at this point).

thanks ... will


Source: (StackOverflow)

How to have a translation service in android app

How can a translation service be called in an Android app? Can we have an app that can translate multiple languages into another?


Source: (StackOverflow)