Jump to content
Sign in to follow this  
lsakizada

How to read or write LOCALE from/to INI file

Recommended Posts

lsakizada

Is there any way to read and write locale strings to/from INI files?

I am interested about section names, keys and values

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
water

If I understand correctly you want to write/read special characters (Umlaut etc.)?

I did a small test and everything seems to work fine:

$sOut = "€öäüÖÄÜß"
IniWrite("test.ini","Locale","Key",$sOut)
$sIn = IniRead("test.ini","Locale","Key","NF")
If $sOut = $sIn Then
    MsgBox(0,"","String is unchanged" & @CRLF & "Out: " & $sOut & @CRLF & "In: " & $sIn)
Else
    MsgBox(0,"","String has changed" & @CRLF & "Out: " & $sOut & @CRLF & "In: " & $sIn)
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
lsakizada

If I understand correctly you want to write/read special characters (Umlaut etc.)?

I did a small test and everything seems to work fine:

$sOut = "€öäüÖÄÜß"
IniWrite("test.ini","Locale","Key",$sOut)
$sIn = IniRead("test.ini","Locale","Key","NF")
If $sOut = $sIn Then
    MsgBox(0,"","String is unchanged" & @CRLF & "Out: " & $sOut & @CRLF & "In: " & $sIn)
Else
    MsgBox(0,"","String has changed" & @CRLF & "Out: " & $sOut & @CRLF & "In: " & $sIn)
EndIf

No I did not meant for that. Your code read locale string from Autoit script and not from ini file.

I want to know if there are some function out there such as iniWriteUTF8, iniReadUTF8, iniReadSectionsUTF8, etc.

So I could use them to store all info such as keys, values and section names in locales.

EDIT: This did not work for me after setting SCITE to use UTF8 encoding

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
water

I see. I think what you want is not possible with pure AutoIt. Please see this post.

But MrCreatoR seems to have written his own ini functions with UTF8 support (or see this post)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
lsakizada

:)

I see. I think what you want is not possible with pure AutoIt. Please see this post.

But MrCreatoR seems to have written his own ini functions with UTF8 support (or see this post)

At this post MrCreator said that it is working with UTF8

I hope in the future it will be possible to IniWrite/Read in "UTF-8 with Signature" encoding (with UTF-8 itself works OK).

Did i understood this note correctly? And why McCreator developed the following functions if it works with UTF8

I found the INIWriteEx() but not the INIReadEx...please whete it is?

_IniWriteEx("C:\1.ini", "1", "1", "Đất nước Việt Nam", 128)

Func _IniWriteEx($sIniFile, $sSection, $sKey, $sValue, $iUTFMode=0)
    If BitOR($iUTFMode, 16, 32, 64, 128) <> Number(16+32+64+128) Then $iUTFMode = 128
    Local $sReadFile = FileRead($sIniFile)
    Local $hFile = FileOpen($sIniFile, 10+$iUTFMode)
    If $hFile = -1 Then Return IniWrite($sIniFile, $sSection, $sKey, $sValue)
    Local $aFileArr = StringSplit(StringStripCR($sReadFile), @LF)
    
    If @error Then
        If $sReadFile <> "" Then $sReadFile &= @LF
        FileWrite($hFile, $sReadFile & "[" & $sSection & "]" & @LF)
        FileWrite($hFile, $sKey & "=" & $sValue)
        FileClose($hFile)
        Return SetError(0, 0, 1)
    EndIf
    
    Local $sLF = @LF, $aSplitKeyValue, $iValueWasWritten = False
    
    For $i = 1 To $aFileArr[0]
        If $i = $aFileArr[0] Then $sLF = ""
        FileWrite($hFile, $aFileArr[$i] & $sLF)
        
        If $aFileArr[$i] = "[" & $sSection & "]" Then
            For $j = $i+1 To $aFileArr[0]
                If $j = $aFileArr[0] Then $sLF = ""
                
                If Not $iValueWasWritten Then
                    If StringRegExp(StringRegExpReplace($aFileArr[$j], '\s+=', '='), $sKey & '=') Then
                        $aSplitKeyValue = StringSplit($aFileArr[$j], "=")
                        FileWrite($hFile, $aSplitKeyValue[1] & "=" & $sValue & $sLF)
                        $iValueWasWritten = True
                    ElseIf $aFileArr[$j] = "" Then
                        FileWrite($hFile, $sKey & "=" & $sValue & $sLF)
                    ElseIf StringLeft($aFileArr[$j], 1) = "[" Or $j = $aFileArr[0] Then
                        FileWrite($hFile, $aFileArr[$j] & @LF & $sKey & "=" & $sValue & $sLF)
                    Else
                        FileWrite($hFile, $aFileArr[$j] & $sLF)
                    EndIf
                Else
                    FileWrite($hFile, $aFileArr[$j] & $sLF)
                EndIf
            Next
            
            ExitLoop
        ElseIf $i = $aFileArr[0] Then
            FileWrite($hFile, @LF & "[" & $sSection & "]" & @LF)
            FileWrite($hFile, $sKey & "=" & $sValue)
        EndIf
    Next
    
    FileClose($hFile)
    Return SetError(0, 0, 1)
EndFunc

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
water

Here you can find the complete UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Tiotua

In German I use this:

#Include <String.au3>

IniWrite("umlauts.ini", "Umlauts", "Example1", _StringToHex("Ich genieße öfter üblen Käse."))
$Result = _HexToString(IniRead("umlauts.ini", "Umlauts", "Example1", ""))
msgbox(64,"Umlauts in INI", $Result)
Exit

Works perfectly. It should also work with Russian, Thai etc. chars. The only "handicap" is: you cannot read the values directly in the INI file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×