Why do people use i18n() and i18nc() instead of qsTr()? - localization

I'm completely new to translating QML widgets.
I see people using i18n() and i18nc() in their source code.
I've found the commands documented here:
https://techbase.kde.org/Development/Tutorials/Localization/i18n#QML
But the QML documentation only lists the qsTr() method. I guess the other 2 commands are KDE specific?
Do I really have to dabble with those KDeclarative etc objects, in C++? I'm not really sure how that works. My widget doesn't use any of that, just qml files and some javascript files for external functions.
I've found out I can get the translation to work with PoEdit but only for .js files, if I define a custom source keyword (function name) to extract from them, but ONLY if they are i18n and i18nc (qsTr doesn't work) and when using a directory structure I stole from a working widget (that is /contents/locale/language_key/plasma_applet_widget_id.mo). Sadly, since the parser getText can't read qml files, this solution isn't good enough.
Now, I know qt provides a command, lupdate, to extract those keywords from the source, but that only works for qsTr, conversely. Trying to pass -tr-function-alias qsTr=(i18n) as an argument doesn't work. With qsTr() I can have a nice .ts file, but trying to convert that to po and use the previously mentioned trick doesn't work.
I wonder though, why the devs of the downloadable widgets all seem to use i18n and i18nc in their source code if lupdate doesn't seem to be able to extract those keywords.

Why do people use i18n and i18nc instead of qsTr?
Probably because it's way more convenient. I've been able to get .qml files to work using the above-mentioned trick by simply manually editing the .po files (referencing the qml file in question, the line where the keyword occurs and so on).

Related

Blink.jl load(loadjs!/loadcss!/importhtml!) functions not working correctly

I hope someone here has used the Blink.jl package for building Julia and Electron apps.
I am having problems setting up and using it, though. The issue is with all of the functions in the api provided: load/loadcss/loadjs/importhtml. They do not seem to work, or I might be doing something wrong.
For example:
loadcss!(w, "styles.css")
does not apply any of the styles in the styles files in the directory.
importhtml!(w, 'index.html')
does not display the html page stored in the local directory. The app shows a blank screen.
I might be doing something wrong as i could not find documentation on how to use the package
I think I found out why, the methods take the full path and not the relative paths, even if files are inside the same folder. So, something like this works:
loadcss!(w, "D:\project\styles.css")
but this won't work:
loadcss!(w, "styles.css")

How do I tell dartdoc to document everything?

I've tried to lay out my classes in one file each, with the classes belonging to a couple different libraries.
Basically, these files have library inf.logic; at the top:
web/logic/realm.dart (imports region.dart)
web/logic/region.dart (imports ../events.dart)
web/logic/tile.dart
This has library inf.gfx;:
web/gfx/viewport.dart (imports ../logic/realm.dart)
This has just library inf;:
web/events.dart
And then I have the main entry point, which seems to end up in the inf library by default:
web/inf.dart (imports gfx/viewport.dart, logic/realm.dart, logic/region.dart, logic/tile.dart)
When I generate dartdoc, it only seems to catch some classes, seemingly randomly. Even though the main entry point uses all of the above classes explicitly, I only get docs generated for region.dart and events.dart. No other files are included, and the links in the doc that refers to the other classes result in 404's.
It feels like I'm doing something wrong. Should I resort to create a wrapper file for the libraries and use part and part of? I really dislike the idea of adding that need for maintenance between file relations, that should already be implicit from the imports.
Also, how can I get rid of relative paths? I tried package:inf/logic/realm.dart, but it doesn't work…
Andrei Mouravski answered this on the mailing list:
There are several issues here:
If Dartdoc is generating 404 links, then file a bug with all information you can possibly provide. It's very possible something broke. dartbug.com/new
You can document multiple things at the same time by passing multiple entrypoints. Note: if you have multiple entrypoints, you should use the 'pkg' command line option to specify your packages folder.
You shouldn't need a wrapper file, but dartdoc should document every library that was imported in the entrypoint, so a possibility is to just have a simple file that imports all the libraries you want documented. We're working on something better for this, and I'm sorry it's a little broken at the moment.

Using LuaDoc with extensions other than .lua

I am currently developing lua scripts for a new application which requires the extension to be xx_lua. I have luadoc working fine for .lua extensions and I know I could simply rename the files to the lua extension create the documents and rename them back, but personally I would prefer a more elegant solution.
Is is possible to get luadoc to look at other extensions. I have tried calling
luadoc_start *.xx_lua
but that results with no output even when there are plenty of files in the path with that extension.
If modifying luadoc is an option then you can do that. I just had a quick look at the 3.0.1 version (latest at the moment of writing this) and in src/luadoc/taglet/standard.lua there's line 406:
local patterns = { "%.lua$", "%.luadoc$" }
The pattern "%.lua" is used at two other locations (same file, line 316) and in src/luadoc/doclet/html.lua:53, that last one doesn't seem relevant. The right thing to do in my opinion would be to create a global parameter for filename extension and use it instead of the hardcoded ".lua". Maybe you can even submit a patch to luadoc and improve it for future programmers in your situation :)

Troubleshooting "call to undefined function" when adding Markdown to project

I'm trying to add some Markdown capabilities to my Symfony project (Symfony version 1.3.3).
To accomplish that, I had already included the Markdown library into lib/vendor directory. Also, I added the need configuration in the autoload.yml for the previous library.
However, I'm getting a fatal PHP error:
Call to undefined function Markdown()
How can I resolve this problem?
The symfony autoloader loads classes from php files named like <classname>.class.php. If you're using the markdown.php file from mitchelf.com, it does not follow the naming scheme, nor does it contain a class called Markdown, as a matter of fact: it has a function called Markdown.
Symfony isn't even trying to load it, for reasons I described above. You will have to include it manually. I suggest you have a look at http://www.symfony-project.org/plugins/sfEasyMarkdownPlugin.
I do NOT suggest installing a plugin for such a simple feature. It is not hard for you to figure it out if you have some real examples.
There is an open source project based on symfony named Bookeet. It has embedded MarkDowm feature. It uses markitup as the markdown editor. And it uses php markdown to convert markdown code to html code.
To save your time, go directly to changeset 29f0ba1807 of the Bookeet project(I am sorry that I can't post the hyperlink because SO doesn't permit new user to post more than one hyperlink). You could see clearly what should be done in order to add markdown feature to your website.

Creating Microsoft Word (.docx) documents in Ruby

Is there an easy way to create Word documents (.docx) in a Ruby application? Actually, in my case it's a Rails application served from a Linux server.
A gem similar to Prawn but for DOCX instead of PDF would be great!
As has been noted, there don't appear to be any libraries to manipulate Open XML documents in Ruby, but OpenXML Developer has complete documentation on the format of Open XML documents.
If what you want is to send a copy of a standard document (like a form letter) customized for each user, it should be fairly simple given that a DOCX is a ZIP file that contains various parts in a directory hierarchy. Have a DOCX "template" that contains all the parts and tree structure that you want to send to all users (with no real content), then simply create new (or modify existing) pieces that contain the user-specific content you want and inject it into the ZIP (DOCX file) before sending it to the user.
For example: You could have document-template.xml that contains Dear [USER-PLACEHOLDER]:. When a user requests the document, you replace [USER-PLACEHOLDER] with the user's name, then add the resulting document.xml to the your-template.docx ZIP file (which would contain all the images and other parts you want in the Word document) and send that resulting document to the user.
Note that if you rename a .docx file to .zip it is trivial to explore the structure and format of the parts inside. You can remove or replace images or other parts very easily with any ZIP manipulation tools or programmatically with code.
Generating a brand new Word document with completely custom content from raw XML would be very difficult without access to an API to make the job easier. If you really need to do that, you might consider installing Mono, then use VB.NET, C# or IronRuby to create your Open XML documents using the Open XML Format SDK 1.0. Since you would just be using the Microsoft.Office.DocumentFormat.OpenXml.Packaging Namespace to manipulate Open XML documents, it should work okay in Mono, which seems to support everything the SDK requires.
Maybe this gem is interesting for you.
https://github.com/trade-informatics/caracal/
It like prawn but with docx.
You can use Apache POI. It is written in Java, but integrates with Ruby as an extension
This is an old question but there's a new answer. If you'd like to turn an HTML doc into a Word (docx) doc, just use the 'htmltoword' gem:
https://github.com/karnov/htmltoword
I'm not sure why there was answer creep and everyone started posting templating solutions, but this answers the OP's question. Just like Prawn, except Word instead of PDF.
UPDATE:
There's also pandoc and an API wrapper for pandoc called docverter. Both have slightly complicated installs since pandoc is a haskell library.
I know if you serve a HTML document as a word document with the .doc extension, it will open in Word just fine. Just don't do anything fancy.
Edit: Here is an example using classic ASP. http://www.aspdev.org/asp/asp-export-word/
Using a technique very similar to that suggested by Grant Wagner I have created a Ruby html to word gem that should allow you to easily output Word docx files from your ruby app. You can check it out at http://github.com/nickfrandsen/htmltoword - Simply pass it a html string and it will create a corresponding word docx file.
def show
respond_to do |format|
format.docx do
file = Htmltoword::Document.create params[:docx_html_source], "file_name.docx"
send_file file.path, :disposition => "attachment"
end
end
end
Hope you find it useful. If you have any problems with it feel free to open a github issue.
Disclosure: I'm the leader of the docxtemplater project.
I know you're looking for a ruby solution, but because all other solutions only tell you how to do it globally, without giving you a library that does exactly what you want, here's a solution based on JS or NodeJS (works in both)
DocxTemplater Library
Demo of the library
You can also use it in the commandline:
npm install docxtemplater -g
docxtemplater <configFile>
----config.docxFile: The input file in docx format
----config.outputFile: The outputfile of the document
This is a way Doccy (doccyapp.com) has a api that does just that which you can use. Supports docx, odt and pages and converts to PDF as well if you like
Further to Grant's answer, you can also send Word a "Flat OPC" file, which is essentially the docx unzipped and concatenated to create a single xml file. This way, you can replace [USER-PLACEHOLDER] in one file and be done with it (ie no zipping or unzipping).
If anyone is still looking at this, this post explains how to use an XML data source. This works nicely for me.
http://seroter.wordpress.com/2009/12/23/populating-word-2007-templates-through-open-xml/
Check out this github repo: https://github.com/jawspeak/ruby-docx-templater
It allows you to create a document from a word template.
If you're running on Windows, of course, it's a matter of WIN32OLE and some pain with the Word COM objects.
Chances are that your serving from a *nix environment, though. Word 2007 uses the "Microsoft Office Open XML" format (*.docx) which can be opened using the appropriate compatibility pack from Microsoft.
Some of the more recent Office apps (2002/XP and 2003 at least) had their own XML formats which may also be useable.
I'm not aware of any Ruby tools to make the process easier, sadly.
If it can be made acceptable, I think I'd be inclined to go down the renamed-html file route. I just saved a document as HTML from WordXP, renamed it to a .doc and opened it without problem.
I encountered the same problem. Unfortunately I could not manipulate the xml because my clients should themselves to fill in templates. And to do this is not always possible (for example, office for mac does not allow this).
As a solution to this problem, I made ​​a simple gem, which can be used as an rtf document template with embedded ruby: https://github.com/eicca/rtf-templater
I tested it and it works ok for filling reports and documents. However, formatting badly displays for complex loops and conditions.

Resources