Changing source files encoding in XCode 4 - xcode

We are developing primarily in C++ under Windows and write comments in Russian. So our OEM encoding is Cyrillic (Windows).
XCode 4 does not ask to specify file encoding when you add existing file to the project. And you can specify your encoding in the right pannel on per file basis.
How am I supposed to change encoding for more than 200 files?
Thank you.

Select the files (one or more) in the Project Navigator. In the Utility pane, under the Text Settings group you can change the Text Encoding.

Click the file in the Project Navigator, then open the Utility pane. Choose the File Inspector tab and look under the Text Settings group to find the Text Encoding popup.

Related

SwitUI iOS localization language is not changing

I localized my app in Xcode 13.2.1 into two languages as shown on picture below - EN texts are hardcoded, CZ texts are in Localizable file (imported from xcloc file).
App is constantly appearing in CZ in Simulator even if I set EN language in Run scheme. The only way I found so far to change appearence to EN is to remove CZ localization from the app at all. Any hint, please? Thanks.
Here's how I was able to fix it:
Select the Localizable.strings file in the project navigator.
In the File Inspector, you'll see "English" being unchecked, you need to mark it checked.
By default, Xcode will copy an existing non-English localization for English, so we need to replace it with the original English translation. Luckily, it's possible to just extract it from the .xloc package.
Select menu Product - Export Localizations, make sure English is checked and run the export.
Open the directory of export in Finder, locate the en.xloc file. Right click on it and choose "Show package contents".
Inside the package, go to Source Contents/%TargetName%/en.lproj.
Inside, you'll see the Localizable.strings file. Copy it into your project, replacing the file that Xcode generated previously.
Rebuild the app.
After doing all that, English localization should be back.

How do I create a .conf file in Mac osx Lion?

I'm using plain text format on text edit and I'm also storing the file as filename.conf but it always ends up getting stored as filename.conf.txt. I've even unchecked the box that says "If no extension is provided, use .txt"
TextEdit just doesn't seem to recognize .conf as an extension?
Any help with this?
Open TextEdit's Preferences, and switch to the Open and Save section. Under the When Saving a File panel, uncheck the Add '.txt' extension to plain text files option.

View .svg files as text in Xcode?

I use xcode for my editing environment. I'm editing a few .svg files on a project, and I need xcode to open the files as text. Rather, it renders the documents as svg. While I appreciate how this helps most of the time (working and view svg's as such) its a hinderance to me right now.
Does anyone know how to tell xcode to treat a .svg file as regular text?
There is a simple way of changing the editor for any file type, particularly SVG in Xcode 5 (I believe this was possible in previous versions too):
Right click on the file in your Project Navigator, choose "Show File Inspector"
In File Inspector change the Type field to, for example, XML:
You will have to do it for each SVG file though. Seeing the graphical preview of your SVG is still possible via right click in Project Navigator -> Open As -> Preview.
In reply to mojuba and using the file inspector, I'm not sure this is what makes the difference but I have Location set to 'Relative to Workspace' (my workspace file and source files are in the same directory) and the settings do survive restarting Xcode. I'm using Xcode 4.2.1.
Renaming to .xml (make sure Finder isn't hiding the real extension by editing the name in the info panel) did work for me — in my case the SVG wasn't part of a project and so #mojumba's trick did not work.
It doesn't appear you can view source for .svg in Xcode, I'd suggest using something like vim or TextEdit.app, both of which are built-in to your system.

xcode doesn't recognize localization in Info.plist

I am using Xcode 4.4.
As you may all know, there is an easy option to localize resource files in Xcode. You can also internationalize your plist Files, which is my approach.
But since 4.4 it doesn't seem to work properly anymore.
All you have to do is the following:
In <project>-Info.plist file add key "Localization" which adds a subarray where you add your country codes as items
now you can localize you resource file (like Localizable.strings) i.e. like so: followed by a modal screen where you're able to choose the languages defined in plist file
Enter! The resource file now lives in <country identifier>.lproj folder.
In Xcode 4.4 you cannot choose your language, defined in plist file. Only English.
I tried everything. Don't want to localize manually.
Also in Xcode versions below 4.4 it was possible to add new languages with a '+'-button. It is not possible:
Look at this:
Any suggestions. Or do I do it just the wrong way?
Here is how you localize your recources in Xcode 4.4+ :
Click on your project (navigator)
On 'Info' tab under your project you'll see the 'Localizations' section
Click on + to add a language
Choose the files you want to localize in the sheet that will be displayed
Now Xcode will automatically create and put your files under the respective language folders.
Finally if you want to localize other sources (such as image files), click on your file, bring the file inspector pane and click 'Make Localized...' button under 'Localization' section. Xcode will fire up another sheet with the available languages, choose the language and you're ready. I hope that this makes sense.
The question is, too, how to localize multiple Info.plist files for multiple targets.
This is done very easily. Just add the languages you want your localization in to the projectile, as described above.
Then you click your several Info.plist Files, each for each target.
Open up the Utilities sidebar
Click "Make localized"
Then choose between the in the project-file setup languages and you're done.

How to set standard encoding in Visual Studio

I am searching for a way to setup Visual Studio so it always saves my files in UTF-8.
I have only found options to set this project wide. Is there a way to set it Visual Studio wide?
Do you want the files to save as UTF-8 because you are using special characters that would be lost in ASCII encoding? If that's the case, then there is a VS2008 global setting in Tools > Options > Environment > Documents, named Save documents as Unicode when data cannot be saved in codepage. When this is enabled, VS2008 will save as Unicode if certain characters cannot be represented in the otherwise-default codepage.
Also, which files are not being saved as UTF-8? All of my .cs, .csproj, .sln, .config, .as*x, etc, all save as UTF-8 (with signature, the byte order marks), by default.
What
It is possible with EditorConfig.
EditorConfig helps developers define and maintain consistent coding
styles between different editors and IDEs.
This also includes file encoding.
EditorConfig is built-in Visual Studio 2017 by default, and I there were plugins available for versions as old as VS2012. Read more from EditorConfig Visual Studio Plugin page.
How
You can set up a EditorConfig configuration file high enough in your folder structure to span all your intended repos (up to your drive root should your files be really scattered everywhere) and configure the setting charset:
charset: set to latin1, utf-8, utf-8-bom, utf-16be or utf-16le to
control the character set.
You can add filters and exceptions etc on every folder level or by file name/type should you wish for finer control.
Once configured then compatible IDEs should automatically do it's thing to make matching files comform to set rules. Note that Visual Studio does not automatically convert all your files but do its bit when you work with files in IDE (open and save).
What next
While you could have a Visual-studio-wide setup, I strongly suggest to still include an EditorConfig root to your solution version control, so that explicit settings are automatically synced to all team members as well. Your drive root editorconfig file can be the fallback should some project not have their own editorconfig files set up yet.
I work with Windows7.
Control Panel - Region and Language - Administrative - Language for non-Unicode programs.
After I set "Change system locale" to English(United States). My default encoding of vs2010 change to Windows-1252. It was gb2312 before.
I created a new .cpp file for a C++ project, after checking in the new file to TFS the encoding show Windows-1252 from the properties page of the file.
The Problem is Windows/Microsoft applications put byte order marks at the beginning of all your files when saving as non-ASCII types (UTF-8, etc.). Other applications often break when they read these odd Microsoft UTF-8 byte order encoding marks at the top of files.
A perfect example of this problem was triggering quirsksmode in old IE web browsers when encoding in UTF-8 as browsers often displayed XHTML web pages based on what encoding falls at the start of the page. It makes a mess when other applications view those UTF-8 Visual Studio pages.
I usually do not recommend Visual Studio Extensions, but I do this one to fix that issue:
Fix File Encoding: https://vlasovstudio.com/fix-file-encoding/
The FixFileEncoding above install REMOVES the byte order mark and forces VS to save ALL FILES without a Byte Order Mark signature in UTF-8 at the top of all .NET pages. After installing go to Tools > Option then choose "FixFileEncoding". It should allow you to set all saves as UTF-8 . Add "cshtml to the list of files to always save in UTF-8 without the byte order mark as so: ".(htm|html|cshtml)$)".
Now open one of your files in Visual Studio. To verify its saving as UTF-8 go to File > Save As, then under the Save button choose "Save With Encoding". It should choose "UNICODE (Save without Signature)" by default from the list of encodings. Now when you save that page it should always save as UTF-8 without byte order mark at the beginning of the file when saving in Visual Studio.
I don't know of a global setting nither but you can try this:
Save all Visual Studio templates in UTF-8
Write a Visual Studio Macro/Addin that will listen to the DocumentSaved event and will save the file in UTF-8 format (if not already).
Put a proxy on your source control that will make sure that new files are always UTF-8.
It is an old topic, but I'll put here what helped me:
Change Visual Studio default encoding

Resources