Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:57:47+00:00 2026-06-15T23:57:47+00:00

The Task My task was to take a php i18n language file and convert

  • 0

The Task

My task was to take a php i18n language file and convert it to a ColdFusion struct. Here is a portion of the input

...
"ASK_DELETE"                =>  "<em>D</em>elete", // 'd' is the accesskey identifier
"BACKUP_OF"                 =>  'Backup of',
"PAGE_TITLE"                =>  "Page Title",
...

Current Attempt at converting

The code below does work for the php language file that I have been handed. The issue is, the code looks like the beginning of spaghetti code. Some of the things I don’t like are

  • If one more string pattern comes along, things will crash
  • I have a variable called “value”
  • Lots of mid string based chopping.

The code looks like the beginning of spaghetti code. What kinds of things should be done about this?

    <cffunction name="readPropertiesFile" returnType="Struct" hint="Read a properties file and return a structure">
    <cfargument name="propertiesFile" type="string" required="true" hint="path to properties file">


    <cfscript>
        VAR stProperties = {};
        VAR phpText = "";
        VAR key = "";
        VAR value = "";
        VAR line = "";

       var propertiesFilePath = "#GetDirectoryFromPath(GetBaseTemplatePath())##arguments.propertiesfile#";


       if (NOT FileExists(propertiesFilePath))

        return stProperties;

     </cfscript>




    <!--- read props file --->
    <cffile action="read" file="#propertiesFilePath#" variable="phpText">



    <!--- remove any whitespace at top and tail --->
    <cfset phpText = trim(phpText)>

    <!--- remove comments and blank lines --->
    <cfset phpText = ReReplace(phpText,"(?m)\##.*?$", "","all")>
    <cfset phpText = ReReplace(phpText,"[#Chr(10)#]{2,}", "#Chr(10)#","all")>
    <cfset phpText = ReplaceList(phpText, '",', '"')>


    <!--- loop over each line, ignore comments (#...) and insert keys/values into return struct --->
    <cfloop list="#phpText#" index="line" delimiters="#CHR(10)#">
    <cfscript>

    line = trim(line);
    splitAt = Find("=>", line);
    CommentAt = Find("//", line);

    if (splitAt != 0)   {

        key =  replacelist(trim(Left(line, splitAt - 1)), '"', "");

        if (CommentAt == 0)
    value = replacelist(trim(Mid(line, splitAt + 2, 1000)), '"', '');
        else
            value = replacelist(trim(Mid(line, splitAt + 2, CommentAt - (splitAt + 2))), '"', '');

        //  Remove trailing , 
    if (right(value, 1) == ",")
            value = mid(value, 1, len(value) - 1);


    if (right(value, 1) == "'")
        value = mid(value, 1, len(value) - 1);


    if (left(value, 1) == "'")
        value = mid(value, 2, 1000);



        stProperties[key] = value;
        } // end if
    </cfscript>
</cfloop>

<cfreturn stProperties>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:57:48+00:00Added an answer on June 15, 2026 at 11:57 pm

    This would be my approach. You can of course make this more resilient or add error trapping to catch inconsistent file parsing. I’m assuming there won’t be quotes in the key values.

    <!--- Going on the Assumption there isn't commas or quotations inside the values of the key --->
    <cfsavecontent variable="fileData">
    
    "ASK_DELETE"                =>  "<em>D</em>elete", // 'd' is the accesskey identifier
    "BACKUP_OF"                 =>  'Backup of',
    
    "PAGE_TITLE"                =>  "Page Title"
    
    </cfsavecontent>
    
    <cfset i18n = structNew()>
    <!--- Remove // Comments --->
    <cfset fileData = REReplace(fileData,"//.*?\n","","ALL")>
    <!--- Simplify Delimiter --->
    <cfset fileData = Replace(fileData,"=>","|","ALL")>
    
    <cfloop list="#fileData#" delimiters="," index="thisEntry">
        <!--- Strip Quotes and Pull Entries --->
        <cfset key = REReplace(ListFirst(thisEntry,"|"),"[""']","","ALL")>
        <cfset value = REReplace(ListLast(thisEntry,"|"),"[""']","","ALL")>
        <cfset structInsert(i18n,trim(key),trim(value))>
    </cfloop>
    
    <cfdump var="#i18n#">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a basic example of how simple_html_dom works in a standalone php file.
I'd like to be able to take a 1-frame SWF file and convert it
Recently I was asked to take over the programming updating task of a php
i am new to php. i need to do a task that convert xml
I am experimenting with this code: foreach (var r in _vm.Rules.Take(20)) { Task.Factory.StartNew(() =>
What would it take to create a TASK card board with mappable states like
This should be an absurdly easy task: I want to take each line of
I have a task to do, I need to take data that has been
I have a task I need to perform, do_stuff(opts) , that will take ~1s
the task I want to achieve is import XML file into SQL Server. Once

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.