Translate string that are unknown at compile time - qt5

I am writing an application which has content that can be added from external sources (through a set of JSON files). Therefore the content to be displayed is mostly unknown at comile time but will be curated (no random sources).
For the content that is known at compile time I can add translations by adding the corresponding tr() guards or QT_TR_NOOPS in the sources where the external content is parsed.
Is there a way to achieve the same for strings that are unknown at compile time? I could add the text for the several translations in the JSON file and write my own code the translation. However I would prefer to have all translations in a central file and use Qt translation code. I would then update the qm file containing the translation together with the JSONs and restart the application.

Related

Dynamic updating text file used for language translation in application using Objective C in iPhone

I have been working on an application which uses text files to dynamic translate strings according to the key value pair provided by service. I am unable to update that file as it is not writable, also file manager fails to delete that file i.e. it returns false when removeItematPath is called. How can it be updated?

Is it possible to refactor string keys when using the Multilingual App Toolkit?

When using the Multilingual App Toolkit (MAT) v4, refactoring a string ID in a reference to a resx string will, as expected, change the ID of that string in all resx files. However, the xlf files are not touched, and when you recompile, MAT will 1) detect the refactored ID as a new string resource, and 2) remove the "old" string resource since it's no longer present in the master resx file.
Is it possible to properly (automatically) refactor string keys when using MAT?
The Multilingual App Toolkit does not support refactoring IDs. The resource ID (and source file) is used as the only unique identifier. Using the source string alone is not considered a reliable identifier alone
the XLF files are updated during the build operation, which is why you see the new/deleted string(s) after the build.
As a workaround, after the build you can import the previous XLF files with the recycling option enabled (Check box on the bottom of the Import UI). The recycling option uses the source string (and other check) to match refactor resources. (Of course, you will need to have a copy in source control or else were to set the previous values)

Creating a search app like EasyFind

On OS X there is a popular app called EasyFind that searches for strings inside of a files content or you can just do a name search. More importantly, it searches in hidden files and inside of package contents.
So my research with using the Spotlight API leads me to believe that it is not possible to do this. Should I assume EasyFind is doing this all manually without using any Cocoa search API?
If that is true, does anyone know of some code to get me started, even just pseudo?
Basically I want to build an app that will find every single image on the drive no matter where it is or what permissions it has. This also includes icon files.
One other thing I can't seem to find an answer to is whether or not you can do a search like this on the command line in OS X.
Thanks!
In the command line you can use the find command line tool. That gives you access to all the files in the filesystem if you run it with root permissions (sudo). You can pipe its results to grep to find for strings inside the files. You can also use the strings command line tool to look for strings inside binary files.
This is not very complicated to implement within a Cocoa App. Just Google for how to iterate through all the hard drive contents. NSFileManager could be a good place to start digging.
Also check out FindAnyFile. It is a nice app that does similar to EasyFind but just on file properties (name, dates, etc.). It doesn't read file contents.

Cocoa Core Data and plain text file

I'm wrinting a very simple application which can read data from a specified file and populate the fetched data to a NSTableView. The file is a plain text file where each line represents an object (I need to parse the file). I want to use Core Data and my question is what is the Cocoa way to do that?
My first idea is to parse the file and create instances for the Entity which represents one line. I'm not sure that is it the best solution. And later I'll write out the changes to the file (after save? or automatically after a given amount of time?)
My configuration is Mountain Lion and the latest XCode.
A single entity with a number of attributes sounds good. If you had an attribute which holds a reasonable amount of data and was repeated on a number of 'rows' then it would be a candidate for another entity.
Yes, each instance of your entity would represent one row in your table.
Personally, I would either save on request by the user, or not have a save button and save each change. Your issue is the conversion between your in-memory store and on-disk store. Using a plain text file doesn't help (though, depending on the file format, it could be possible to edit individual lines in the file using NSFileHandle).
Generally it would still make more sense to use a better format like XML or JSON and then make use of a framework like RestKit which will do all of the parsing and mapping for you (after you specify the mapping configuration).
You can also use bindings to connect your data to your NSTableView. Another ref.

Recommended document structure. File Wrappers? Roll my own?

I'm currently working out the best structure for a document I'm trying to create. The document is basically a core data document that uses sqlite as its store, but uses the Apple provided NSPersistentDocument+FileWrapperSupport to enable file wrapper support.
The document makes heavy use of media, such as images, videos, audio files, etc. with potentially 1000s of files. So what I'm trying to do is create a structure similar to the following:
/myfile.ext/
/myfile.ext/store.sqlite
/myfile.ext/content/
/myfile.ext/content/images/*
/myfile.ext/content/videos/*
/myfile.ext/content/audio/*
Now, first of all I went down the route of creating a temporary directory and placing all of my media in there. Basically creating the paths and file names '/content/images/image1.jpg' as I wanted them to appear in the saved file wrapper, and then upon save I attempted to copy these all into the filewrapper...
What I found was that the files were indeed copied into the wrapper with the file structure I wanted, but when the actual wrapper was saved, these files all magically disappeared.
Great.
So, I trashed my existing solution and tried to use file wrappers instead. This solution involved creating a content wrapper file directory when a new document was created, or loading in a content directory file wrapper upon opening a document.
When an image was added/modified, I created the necessary directory wrappers inside this root content wrapper (i.e. an images directory wrapper if it didn't already exist, or any other intermediary directory wrappers that needed to be created) and then created a regular file wrapper for the media, removing any existing wrapper for that file name if one was there.
Saving the document was just a case of making sure the content file wrapper was added to the document file wrapper, and the document would save.
Well... it did. The first time. However, any attempts to make any subsequent changes i.e add an image, save. Then replace image, save. Did not behave as expected, only showing the image from the first save.
So, my question is... first of all, which of the above approaches is the correct one, if at all, and what am I doing that wrong for them to fail.
And secondly, as I expect to be managing 1000s of images, is using file wrappers the correct way to go about things at all.
With that much media in play, you should likely give your users control over whether the media resides in the document or only a reference to the media is included in the document, and the media resides elsewhere, such as in a library/repository managed by your application. Then they could save out a (potentially many times larger) copy with all references resolved.
You might want to zip/unzip any directory so that users don't get confused trying to attach the document to an email. I believe iWork has been doing this with its document bundles for a while now.
As far as what you are doing wrong, no-one can say, as you haven't provided any code demonstrating what you are doing.
Why don't you create a one-off application that lets you select files on disk and saves those files in a document using a file wrapper? This would let you tackle this functionality without any interference from other issues in your application. Once you understand how to use file wrappers, you can port the code back or just write new code that works.