NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code hint question (codeinsight to include specific files)
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Hi.

I use language files which basically is PHP files with variables like:

(File named english.php)
$LANGUAGE_HOUSE = "House";

(File named danish.php)
$LANGUAGE_HOUSE = "Hus";

In my code I have a static class that gets a language as parameter and includes the correct language file. example
If the language is set to Danish like $language = 'danish';

configs::getLanguage($language);

This will make sure that the correct language file is included.

Now my problem is that PHPEd does not know that configs::getLanguage($language); will include a specific language file, so I do not get code insight (code completeion) on the language variables.

Is there a trick, that I can use to get PHPed to display code completion for the variables in the language files?

Thanks.
View user's profileFind all posts by hgrSend private message
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Ok I have tried to include the directory that holds the language files in the project property settings.

But that did not make code insight work on these language variables.
I have looked in the explorer, and I can find the variables there, so PHPed knows about their existence, but it does not show them on the code insight lookup.

???
View user's profileFind all posts by hgrSend private message
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Ok I don't understand this.

The language files used to be

english.php
DEFINE('LANGUAGE_HOUSE','House');

danish.php
DEFINE('LANGUAGE_HOUSE','Hus');

And when I used DEFINES the code completion worked.
Now I have changed it to variables instead of defines, and now code completion does not work???

The files now look like this.

english.php
$LANGUAGE_HOUSE = 'House';

danish.php
$LANGUAGE_HOUSE = 'Hus';

And I honestly don't understand why code completion worked when it was DEFINE's and now that it is variables it does not?
If I create a new file, the code completion works fine. Even with the new variables. But in one specific file it does not work on these variables.

Normally this can be because of a syntax error, but the rest of code completion works, just not these variables. I am still able to code complete on the rest of the code, just not these variables. ??
View user's profileFind all posts by hgrSend private message
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Ok I think this is a standard feature / Annoyance or bug.

Code completion works if I access the variables outside a class.

Look at the first image.


I know that the names are not the once that I wrote in my previous post, but anyhow.

Notice that the $BIZ_* variables are visible in code completion outside an class

But the second I use it inside a class it stops working.




In some silly way it makes sense, because the variable is not declared GLOBAL so they are treated like local variables, so in other words they do not have scope inside a class, but the trouble is that if this is the reason, they notice the include("c:/blalbal"); on the line above, that will include the variables, and that gives them scope inside the class so it should work.

These are my settings.




I noticed that only Global variables, DEFINES and local variables has a setting and so it works. Which is great because you do not want code completion to display too much. But it also makes it impossible to include a file with variables inside a class and still have code completion working.

So I think its an annoyance in PHPed, and I am back to my initial post. Is there a way that I can force PHPed to include specific files so code completion can work inside classes, on variables defined in external files but included by code???

I really hope there is some sort of code hint, cause I use these language files alot, everything has to be I18N.

Hope to hear from you soon, cause I am unable to solve it.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
Quote:
it also makes it impossible to include a file with variables inside a class and still have code completion working

correct.
When PhpED parses a file, it does not know how this file is used in the project. Generally speaking it can be included in a global context, in a function, in a class method, or not included at all. First and last cases are the most common and they make global all the variables out of functions/methods. Hence, we made a decision to consider all the variables out of the functions and methods as global and once they are considered global, Code Insight won't show them until you add global keyword and list all the names. It works just like you include the language file out of the method in your sample.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Hi Dmitri.

Is there some way to solve this, some other way than to use global variables to get code insight to show the variables.

Like the "Code Insight Includes" in the property settings?

I use this feature to get PDO code completion to work, so I thought that If I add the directory where my language files where kept, it would always include the files in that directory as well, but it does not.

Actually I do not know if there is a bug in there, because I am not able to add more than one folder to the "Code Insight Includes" field.

If I add additional directories, it just ignore them when the Project properties window is closed.
See the attached images.

1. I open the project properties.



2. I add the folder where my language files are kept.



3. The project properties before it is saved. It shows the new folder as added to the code insight.



4. I reopen the project properties to find that the added folder is not saved.




I hope it can be possible to use this feature to get the code insight to work like I need it.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
Quote:
Is there some way to solve this, some other way than to use global variables to get code insight to show the variables.

I'd tell you so. No, there is no way. Sorry if I did not make it clear.
Once again, as of PhpED version 5.2: if you have variables in the global scope of a script, code insight has no clue that they may be local in some functions.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Hi Dmitri, what about my comments regarding the "code insight includes" is that not a possible way? and Have I discovered a bug there?

Not to piss you off, I understand the word (NO WAY Smile ) I am only trying to find a way of working effective with localized php development, without using global variables, or constants like DEFINE, in the interest, of saving memory on the server.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
DEFINE takes exactly the same amount of memory as a regular variable.
Regarding code insight includes, I can't reproduce any problems. Make sure that all the directories you added exist.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Ok.

So if I could get the "code insight Includes" to include more directories, then it will work? I don't understand why it does not work. I am not writing the paths by hand, but are using the GUI tools in PHPed to include the folder?

And Yes, Defines take up the exact number of bytes.
However, Defines will stay in memory, while the variables will be removed from memory when your class gets garbage collected.

I used to use DEFINE, but what is the point in having constants in memory that are not used.

So I decided to create files with variables and then include the files in the classes where they are used. But this has the cost that I can't use code insight, which is a shame, because if I write the variables wrongly, PHP will just create a local empty variable.

So it gets harder to find my mistakes, because there is no runtime error.

It is strange that there is no "best practice" when it comes to i18n in PHP. PHP does not have any real build in support of creating multi language scripts, and because of this, there is no great support for it in any development environment. Sad

Strange that this is such an uncommon problem in PHP.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
Quote:
I am not writing the paths by hand, but are using the GUI tools in PHPed to include the folder?

I did not notice any problems when checked this functionality. Please check if project file <project name>.ppj is not readonly.

Quote:
And Yes, Defines take up the exact number of bytes.
However, Defines will stay in memory, while the variables will be removed from memory when your class gets garbage collected

if you need the messages defined only during class instance life-time, why don't you use class constants then?

Quote:
So I decided to create files with variables and then include the files in the classes where they are used.

Including a file in a function or method is a bit quirky. Global variables appear local, global functions stay global, etc.

Quote:
PHP does not have any real build in support of creating multi language scripts,

I'd just point to gettext php extension. All magic happens inside _() function call and it works quite fast:

Code:
<?php
  // prepare:
  setlocale(LC_ALL, 'de_DE');
  bindtextdomain("myPHPApp", "./locale");
  textdomain("myPHPApp");

  // translate on the fly:
  echo _("Have a nice day");
?>


(certainly you have to prepare translation files with gettext tools)

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Code hint question (codeinsight to include specific files)
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic